/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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-08-05 18:56:37 UTC
  • mfrom: (4580.5.16 1.18-win32-buildbot)
  • Revision ID: pqm@pqm.ubuntu.com-20090805185637-3f0y10upzcdw7e0g
Updates to buildout.cfg etc to have 'make installer-all' start being
        the preferred way to build win32 installer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#            and others
4
4
#
153
153
        """Get the users pop up editor."""
154
154
        raise NotImplementedError
155
155
 
156
 
    def get_change_editor(self, old_tree, new_tree):
157
 
        from bzrlib import diff
158
 
        cmd = self._get_change_editor()
159
 
        if cmd is None:
160
 
            return None
161
 
        return diff.DiffFromTool.from_string(cmd, old_tree, new_tree,
162
 
                                             sys.stdout)
163
 
 
164
 
 
165
156
    def get_mail_client(self):
166
157
        """Get a mail client to use"""
167
158
        selected_client = self.get_user_option('mail_client')
190
181
        """Get a generic option as a boolean - no special process, no default.
191
182
 
192
183
        :return None if the option doesn't exist or its value can't be
193
 
            interpreted as a boolean. Returns True or False otherwise.
 
184
            interpreted as a boolean. Returns True or False ortherwise.
194
185
        """
195
186
        s = self._get_user_option(option_name)
196
 
        if s is None:
197
 
            # The option doesn't exist
198
 
            return None
199
 
        val = ui.bool_from_string(s)
200
 
        if val is None:
201
 
            # The value can't be interpreted as a boolean
202
 
            trace.warning('Value "%s" is not a boolean for "%s"',
203
 
                          s, option_name)
204
 
        return val
205
 
 
206
 
    def get_user_option_as_list(self, option_name):
207
 
        """Get a generic option as a list - no special process, no default.
208
 
 
209
 
        :return None if the option doesn't exist. Returns the value as a list
210
 
            otherwise.
211
 
        """
212
 
        l = self._get_user_option(option_name)
213
 
        if isinstance(l, (str, unicode)):
214
 
            # A single value, most probably the user forgot the final ','
215
 
            l = [l]
216
 
        return l
 
187
        return ui.bool_from_string(s)
217
188
 
218
189
    def gpg_signing_command(self):
219
190
        """What program should be used to sign signatures?"""
257
228
 
258
229
        Something similar to 'Martin Pool <mbp@sourcefrog.net>'
259
230
 
260
 
        $BZR_EMAIL can be set to override this, then
 
231
        $BZR_EMAIL can be set to override this (as well as the
 
232
        deprecated $BZREMAIL), then
261
233
        the concrete policy type is checked, and finally
262
234
        $EMAIL is examined.
263
 
        If no username can be found, errors.NoWhoami exception is raised.
 
235
        If none is found, a reasonable default is (hopefully)
 
236
        created.
264
237
 
265
238
        TODO: Check it's reasonably well-formed.
266
239
        """
276
249
        if v:
277
250
            return v.decode(osutils.get_user_encoding())
278
251
 
279
 
        raise errors.NoWhoami()
280
 
 
281
 
    def ensure_username(self):
282
 
        """Raise errors.NoWhoami if username is not set.
283
 
 
284
 
        This method relies on the username() function raising the error.
285
 
        """
286
 
        self.username()
 
252
        name, email = _auto_user_id()
 
253
        if name:
 
254
            return '%s <%s>' % (name, email)
 
255
        else:
 
256
            return email
287
257
 
288
258
    def signature_checking(self):
289
259
        """What is the current policy for signature checking?."""
334
304
                path = 'bzr'
335
305
            return path
336
306
 
337
 
    def suppress_warning(self, warning):
338
 
        """Should the warning be suppressed or emitted.
339
 
 
340
 
        :param warning: The name of the warning being tested.
341
 
 
342
 
        :returns: True if the warning should be suppressed, False otherwise.
343
 
        """
344
 
        warnings = self.get_user_option_as_list('suppress_warnings')
345
 
        if warnings is None or warning not in warnings:
346
 
            return False
347
 
        else:
348
 
            return True
349
 
 
350
307
 
351
308
class IniBasedConfig(Config):
352
309
    """A configuration policy that draws from ini files."""
389
346
        """Return the policy for the given (section, option_name) pair."""
390
347
        return POLICY_NONE
391
348
 
392
 
    def _get_change_editor(self):
393
 
        return self.get_user_option('change_editor')
394
 
 
395
349
    def _get_signature_checking(self):
396
350
        """See Config._get_signature_checking."""
397
351
        policy = self._get_user_option('check_signatures')
519
473
        self._write_config_file()
520
474
 
521
475
    def _write_config_file(self):
522
 
        path = self._get_filename()
523
 
        f = open(path, 'wb')
524
 
        osutils.copy_ownership_from_path(path)
 
476
        f = open(self._get_filename(), 'wb')
525
477
        self._get_parser().write(f)
526
478
        f.close()
527
479
 
727
679
 
728
680
        return self._get_best_value('_get_user_id')
729
681
 
730
 
    def _get_change_editor(self):
731
 
        return self._get_best_value('_get_change_editor')
732
 
 
733
682
    def _get_signature_checking(self):
734
683
        """See Config._get_signature_checking."""
735
684
        return self._get_best_value('_get_signature_checking')
821
770
            os.mkdir(parent_dir)
822
771
        trace.mutter('creating config directory: %r', path)
823
772
        os.mkdir(path)
824
 
        osutils.copy_ownership_from_path(path)
825
773
 
826
774
 
827
775
def config_dir():
873
821
    return osutils.pathjoin(config_dir(), 'ignore')
874
822
 
875
823
 
876
 
def crash_dir():
877
 
    """Return the directory name to store crash files.
878
 
 
879
 
    This doesn't implicitly create it.
880
 
 
881
 
    On Windows it's in the config directory; elsewhere it's /var/crash
882
 
    which may be monitored by apport.  It can be overridden by
883
 
    $APPORT_CRASH_DIR.
 
824
def _auto_user_id():
 
825
    """Calculate automatic user identification.
 
826
 
 
827
    Returns (realname, email).
 
828
 
 
829
    Only used when none is set in the environment or the id file.
 
830
 
 
831
    This previously used the FQDN as the default domain, but that can
 
832
    be very slow on machines where DNS is broken.  So now we simply
 
833
    use the hostname.
884
834
    """
 
835
    import socket
 
836
 
885
837
    if sys.platform == 'win32':
886
 
        return osutils.pathjoin(config_dir(), 'Crash')
887
 
    else:
888
 
        # XXX: hardcoded in apport_python_hook.py; therefore here too -- mbp
889
 
        # 2010-01-31
890
 
        return os.environ.get('APPORT_CRASH_DIR', '/var/crash')
891
 
 
892
 
 
893
 
def xdg_cache_dir():
894
 
    # See http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
895
 
    # Possibly this should be different on Windows?
896
 
    e = os.environ.get('XDG_CACHE_DIR', None)
897
 
    if e:
898
 
        return e
899
 
    else:
900
 
        return os.path.expanduser('~/.cache')
 
838
        name = win32utils.get_user_name_unicode()
 
839
        if name is None:
 
840
            raise errors.BzrError("Cannot autodetect user name.\n"
 
841
                                  "Please, set your name with command like:\n"
 
842
                                  'bzr whoami "Your Name <name@domain.com>"')
 
843
        host = win32utils.get_host_name_unicode()
 
844
        if host is None:
 
845
            host = socket.gethostname()
 
846
        return name, (name + '@' + host)
 
847
 
 
848
    try:
 
849
        import pwd
 
850
        uid = os.getuid()
 
851
        try:
 
852
            w = pwd.getpwuid(uid)
 
853
        except KeyError:
 
854
            raise errors.BzrCommandError('Unable to determine your name.  '
 
855
                'Please use "bzr whoami" to set it.')
 
856
 
 
857
        # we try utf-8 first, because on many variants (like Linux),
 
858
        # /etc/passwd "should" be in utf-8, and because it's unlikely to give
 
859
        # false positives.  (many users will have their user encoding set to
 
860
        # latin-1, which cannot raise UnicodeError.)
 
861
        try:
 
862
            gecos = w.pw_gecos.decode('utf-8')
 
863
            encoding = 'utf-8'
 
864
        except UnicodeError:
 
865
            try:
 
866
                encoding = osutils.get_user_encoding()
 
867
                gecos = w.pw_gecos.decode(encoding)
 
868
            except UnicodeError:
 
869
                raise errors.BzrCommandError('Unable to determine your name.  '
 
870
                   'Use "bzr whoami" to set it.')
 
871
        try:
 
872
            username = w.pw_name.decode(encoding)
 
873
        except UnicodeError:
 
874
            raise errors.BzrCommandError('Unable to determine your name.  '
 
875
                'Use "bzr whoami" to set it.')
 
876
 
 
877
        comma = gecos.find(',')
 
878
        if comma == -1:
 
879
            realname = gecos
 
880
        else:
 
881
            realname = gecos[:comma]
 
882
        if not realname:
 
883
            realname = username
 
884
 
 
885
    except ImportError:
 
886
        import getpass
 
887
        try:
 
888
            user_encoding = osutils.get_user_encoding()
 
889
            realname = username = getpass.getuser().decode(user_encoding)
 
890
        except UnicodeDecodeError:
 
891
            raise errors.BzrError("Can't decode username as %s." % \
 
892
                    user_encoding)
 
893
 
 
894
    return realname, (username + '@' + socket.gethostname())
901
895
 
902
896
 
903
897
def parse_username(username):
1345
1339
 
1346
1340
 
1347
1341
class PlainTextCredentialStore(CredentialStore):
1348
 
    __doc__ = """Plain text credential store for the authentication.conf file"""
 
1342
    """Plain text credential store for the authentication.conf file."""
1349
1343
 
1350
1344
    def decode_password(self, credentials):
1351
1345
        """See CredentialStore.decode_password."""
1440
1434
 
1441
1435
    def _get_config_file(self):
1442
1436
        try:
1443
 
            return StringIO(self._transport.get_bytes(self._filename))
 
1437
            return self._transport.get(self._filename)
1444
1438
        except errors.NoSuchFile:
1445
1439
            return StringIO()
1446
1440