/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: John Arbash Meinel
  • Date: 2010-01-06 17:46:15 UTC
  • mto: (4634.119.1 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: john@arbash-meinel.com-20100106174615-cq1nckxhbuyemgjx
Fix bug #503886, errors setting up logging go to stderr.

The basic issue is that we were using logging to describe failures
to set up logging. However, those fail with bad error messages
rather than giving us the output we want. This was especially bad
when the failure was occuring on the server. Since 'ssh' will pass
back the stderr stream without bzr handling it at all.

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?"""
333
304
                path = 'bzr'
334
305
            return path
335
306
 
336
 
    def suppress_warning(self, warning):
337
 
        """Should the warning be suppressed or emitted.
338
 
 
339
 
        :param warning: The name of the warning being tested.
340
 
 
341
 
        :returns: True if the warning should be suppressed, False otherwise.
342
 
        """
343
 
        warnings = self.get_user_option_as_list('suppress_warnings')
344
 
        if warnings is None or warning not in warnings:
345
 
            return False
346
 
        else:
347
 
            return True
348
 
 
349
307
 
350
308
class IniBasedConfig(Config):
351
309
    """A configuration policy that draws from ini files."""
388
346
        """Return the policy for the given (section, option_name) pair."""
389
347
        return POLICY_NONE
390
348
 
391
 
    def _get_change_editor(self):
392
 
        return self.get_user_option('change_editor')
393
 
 
394
349
    def _get_signature_checking(self):
395
350
        """See Config._get_signature_checking."""
396
351
        policy = self._get_user_option('check_signatures')
518
473
        self._write_config_file()
519
474
 
520
475
    def _write_config_file(self):
521
 
        path = self._get_filename()
522
 
        f = open(path, 'wb')
523
 
        osutils.copy_ownership_from_path(path)
 
476
        f = open(self._get_filename(), 'wb')
524
477
        self._get_parser().write(f)
525
478
        f.close()
526
479
 
726
679
 
727
680
        return self._get_best_value('_get_user_id')
728
681
 
729
 
    def _get_change_editor(self):
730
 
        return self._get_best_value('_get_change_editor')
731
 
 
732
682
    def _get_signature_checking(self):
733
683
        """See Config._get_signature_checking."""
734
684
        return self._get_best_value('_get_signature_checking')
820
770
            os.mkdir(parent_dir)
821
771
        trace.mutter('creating config directory: %r', path)
822
772
        os.mkdir(path)
823
 
        osutils.copy_ownership_from_path(path)
824
773
 
825
774
 
826
775
def config_dir():
877
826
 
878
827
    This doesn't implicitly create it.
879
828
 
880
 
    On Windows it's in the config directory; elsewhere it's /var/crash
881
 
    which may be monitored by apport.  It can be overridden by
882
 
    $APPORT_CRASH_DIR.
 
829
    On Windows it's in the config directory; elsewhere in the XDG cache directory.
883
830
    """
884
831
    if sys.platform == 'win32':
885
832
        return osutils.pathjoin(config_dir(), 'Crash')
886
833
    else:
887
 
        # XXX: hardcoded in apport_python_hook.py; therefore here too -- mbp
888
 
        # 2010-01-31
889
 
        return os.environ.get('APPORT_CRASH_DIR', '/var/crash')
 
834
        return osutils.pathjoin(xdg_cache_dir(), 'crash')
890
835
 
891
836
 
892
837
def xdg_cache_dir():
1417
1362
 
1418
1363
 
1419
1364
class PlainTextCredentialStore(CredentialStore):
1420
 
    __doc__ = """Plain text credential store for the authentication.conf file"""
 
1365
    """Plain text credential store for the authentication.conf file."""
1421
1366
 
1422
1367
    def decode_password(self, credentials):
1423
1368
        """See CredentialStore.decode_password."""
1512
1457
 
1513
1458
    def _get_config_file(self):
1514
1459
        try:
1515
 
            return StringIO(self._transport.get_bytes(self._filename))
 
1460
            return self._transport.get(self._filename)
1516
1461
        except errors.NoSuchFile:
1517
1462
            return StringIO()
1518
1463