~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-08 08:03:35 UTC
  • mfrom: (6123.1.14 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6252.
  • Revision ID: v.ladeuil+lp@free.fr-20110908080335-ddel4ir5grz945xa
Merge into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1397
1397
            return (self.branch._transport.get_bytes("email")
1398
1398
                    .decode(osutils.get_user_encoding())
1399
1399
                    .rstrip("\r\n"))
1400
 
        except errors.NoSuchFile, e:
 
1400
        except (errors.NoSuchFile, errors.PermissionDenied), e:
1401
1401
            pass
1402
1402
 
1403
1403
        return self._get_best_value('_get_user_id')
2278
2278
            return f
2279
2279
        except errors.NoSuchFile:
2280
2280
            return StringIO()
 
2281
        except errors.PermissionDenied, e:
 
2282
            trace.warning("Permission denied while trying to open "
 
2283
                "configuration file %s.", urlutils.unescape_for_display(
 
2284
                urlutils.join(self._transport.base, self._filename), "utf-8"))
 
2285
            return StringIO()
2281
2286
 
2282
2287
    def _external_url(self):
2283
2288
        return urlutils.join(self._transport.external_url(), self._filename)
2704
2709
        """Load the store from the associated file."""
2705
2710
        if self.is_loaded():
2706
2711
            return
2707
 
        content = self.transport.get_bytes(self.file_name)
 
2712
        try:
 
2713
            content = self.transport.get_bytes(self.file_name)
 
2714
        except errors.PermissionDenied:
 
2715
            trace.warning("Permission denied while trying to load "
 
2716
                          "configuration store %s.", self.external_url())
 
2717
            raise
2708
2718
        self._load_from_string(content)
2709
2719
        for hook in ConfigHooks['load']:
2710
2720
            hook(self)
2753
2763
        # We need a loaded store
2754
2764
        try:
2755
2765
            self.load()
2756
 
        except errors.NoSuchFile:
2757
 
            # If the file doesn't exist, there is no sections
 
2766
        except (errors.NoSuchFile, errors.PermissionDenied):
 
2767
            # If the file can't be read, there is no sections
2758
2768
            return
2759
2769
        cobj = self._config_obj
2760
2770
        if cobj.scalars:
2881
2891
class SectionMatcher(object):
2882
2892
    """Select sections into a given Store.
2883
2893
 
2884
 
    This intended to be used to postpone getting an iterable of sections from a
2885
 
    store.
 
2894
    This is intended to be used to postpone getting an iterable of sections
 
2895
    from a store.
2886
2896
    """
2887
2897
 
2888
2898
    def __init__(self, store):
2897
2907
            if self.match(s):
2898
2908
                yield s
2899
2909
 
2900
 
    def match(self, secion):
 
2910
    def match(self, section):
 
2911
        """Does the proposed section match.
 
2912
 
 
2913
        :param section: A Section object.
 
2914
 
 
2915
        :returns: True if the section matches, False otherwise.
 
2916
        """
2901
2917
        raise NotImplementedError(self.match)
2902
2918
 
2903
2919
 
 
2920
class NameMatcher(SectionMatcher):
 
2921
 
 
2922
    def __init__(self, store, section_id):
 
2923
        super(NameMatcher, self).__init__(store)
 
2924
        self.section_id = section_id
 
2925
 
 
2926
    def match(self, section):
 
2927
        return section.id == self.section_id
 
2928
 
 
2929
 
2904
2930
class LocationSection(Section):
2905
2931
 
2906
2932
    def __init__(self, section, length, extra_path):