/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/config.py

merge bzr.dev r4042

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
[/home/robertc/source]
38
38
recurse=False|True(default)
39
39
email= as above
40
 
check_signatures= as above 
 
40
check_signatures= as above
41
41
create_signatures= as above.
42
42
 
43
43
explanation of options
45
45
editor - this option sets the pop up editor to use during commits.
46
46
email - this option sets the user id bzr will use when committing.
47
47
check_signatures - this option controls whether bzr will require good gpg
48
 
                   signatures, ignore them, or check them if they are 
 
48
                   signatures, ignore them, or check them if they are
49
49
                   present.
50
 
create_signatures - this option controls whether bzr will always create 
 
50
create_signatures - this option controls whether bzr will always create
51
51
                    gpg signatures, never create them, or create them if the
52
52
                    branch is configured to require them.
53
53
log_format - this option sets the default log format.  Possible values are
78
78
    errors,
79
79
    mail_client,
80
80
    osutils,
 
81
    registry,
81
82
    symbol_versioning,
82
83
    trace,
83
84
    ui,
215
216
 
216
217
    def username(self):
217
218
        """Return email-style username.
218
 
    
 
219
 
219
220
        Something similar to 'Martin Pool <mbp@sourcefrog.net>'
220
 
        
 
221
 
221
222
        $BZR_EMAIL can be set to override this (as well as the
222
223
        deprecated $BZREMAIL), then
223
224
        the concrete policy type is checked, and finally
224
225
        $EMAIL is examined.
225
226
        If none is found, a reasonable default is (hopefully)
226
227
        created.
227
 
    
 
228
 
228
229
        TODO: Check it's reasonably well-formed.
229
230
        """
230
231
        v = os.environ.get('BZR_EMAIL')
384
385
        super(IniBasedConfig, self).__init__()
385
386
        self._get_filename = get_filename
386
387
        self._parser = None
387
 
        
 
388
 
388
389
    def _post_commit(self):
389
390
        """See Config.post_commit."""
390
391
        return self._get_user_option('post_commit')
413
414
 
414
415
    def _get_alias(self, value):
415
416
        try:
416
 
            return self._get_parser().get_value("ALIASES", 
 
417
            return self._get_parser().get_value("ALIASES",
417
418
                                                value)
418
419
        except KeyError:
419
420
            pass
641
642
 
642
643
    def _get_safe_value(self, option_name):
643
644
        """This variant of get_best_value never returns untrusted values.
644
 
        
 
645
 
645
646
        It does not return values from the branch data, because the branch may
646
647
        not be controlled by the user.
647
648
 
656
657
 
657
658
    def _get_user_id(self):
658
659
        """Return the full user id for the branch.
659
 
    
 
660
 
660
661
        e.g. "John Hacker <jhacker@example.com>"
661
662
        This is looked up in the email controlfile for the branch.
662
663
        """
666
667
                    .rstrip("\r\n"))
667
668
        except errors.NoSuchFile, e:
668
669
            pass
669
 
        
 
670
 
670
671
        return self._get_best_value('_get_user_id')
671
672
 
672
673
    def _get_signature_checking(self):
712
713
    def _gpg_signing_command(self):
713
714
        """See Config.gpg_signing_command."""
714
715
        return self._get_safe_value('_gpg_signing_command')
715
 
        
 
716
 
716
717
    def __init__(self, branch):
717
718
        super(BranchConfig, self).__init__()
718
719
        self._location_config = None
719
720
        self._branch_data_config = None
720
721
        self._global_config = None
721
722
        self.branch = branch
722
 
        self.option_sources = (self._get_location_config, 
 
723
        self.option_sources = (self._get_location_config,
723
724
                               self._get_branch_data_config,
724
725
                               self._get_global_config)
725
726
 
767
768
    """Return per-user configuration directory.
768
769
 
769
770
    By default this is ~/.bazaar/
770
 
    
 
771
 
771
772
    TODO: Global option --config-dir to override this.
772
773
    """
773
774
    base = os.environ.get('BZR_HOME', None)
897
898
def extract_email_address(e):
898
899
    """Return just the address part of an email string.
899
900
 
900
 
    That is just the user@domain part, nothing else. 
 
901
    That is just the user@domain part, nothing else.
901
902
    This part is required to contain only ascii characters.
902
903
    If it can't be extracted, raises an error.
903
904
 
917
918
 
918
919
    def __init__(self, branch):
919
920
        # XXX: Really this should be asking the branch for its configuration
920
 
        # data, rather than relying on a Transport, so that it can work 
 
921
        # data, rather than relying on a Transport, so that it can work
921
922
        # more cleanly with a RemoteBranch that has no transport.
922
923
        self._config = TransportConfig(branch._transport, 'branch.conf')
923
924
        self.branch = branch
1176
1177
        return password
1177
1178
 
1178
1179
    def decode_password(self, credentials, encoding):
 
1180
        try:
 
1181
            cs = credential_store_registry.get_credential_store(encoding)
 
1182
        except KeyError:
 
1183
            raise ValueError('%r is not a known password_encoding' % encoding)
 
1184
        credentials['password'] = cs.decode_password(credentials)
1179
1185
        return credentials
1180
1186
 
1181
1187
 
 
1188
class CredentialStoreRegistry(registry.Registry):
 
1189
    """A class that registers credential stores.
 
1190
 
 
1191
    A credential store provides access to credentials via the password_encoding
 
1192
    field in authentication.conf sections.
 
1193
 
 
1194
    Except for stores provided by bzr itself,most stores are expected to be
 
1195
    provided by plugins that will therefore use
 
1196
    register_lazy(password_encoding, module_name, member_name, help=help,
 
1197
    info=info) to install themselves.
 
1198
    """
 
1199
 
 
1200
    def get_credential_store(self, encoding=None):
 
1201
        cs = self.get(encoding)
 
1202
        if callable(cs):
 
1203
            cs = cs()
 
1204
        return cs
 
1205
 
 
1206
 
 
1207
credential_store_registry = CredentialStoreRegistry()
 
1208
 
 
1209
 
 
1210
class CredentialStore(object):
 
1211
    """An abstract class to implement storage for credentials"""
 
1212
 
 
1213
    def decode_password(self, credentials):
 
1214
        """Returns a password for the provided credentials in clear text."""
 
1215
        raise NotImplementedError(self.decode_password)
 
1216
 
 
1217
 
 
1218
class PlainTextCredentialStore(CredentialStore):
 
1219
    """Plain text credential store for the authentication.conf file."""
 
1220
 
 
1221
    def decode_password(self, credentials):
 
1222
        """See CredentialStore.decode_password."""
 
1223
        return credentials['password']
 
1224
 
 
1225
 
 
1226
credential_store_registry.register('plain', PlainTextCredentialStore,
 
1227
                                   help=PlainTextCredentialStore.__doc__)
 
1228
credential_store_registry.default_key = 'plain'
 
1229
 
 
1230
 
1182
1231
class BzrDirConfig(object):
1183
1232
 
1184
1233
    def __init__(self, transport):