~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-21 21:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091021212719-05zh4t7oo5kaird3
More cleanups and clarifications.

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
187
        return ui.bool_from_string(s)
197
188
 
198
 
    def get_user_option_as_list(self, option_name):
199
 
        """Get a generic option as a list - no special process, no default.
200
 
 
201
 
        :return None if the option doesn't exist. Returns the value as a list
202
 
            otherwise.
203
 
        """
204
 
        l = self._get_user_option(option_name)
205
 
        if isinstance(l, (str, unicode)):
206
 
            # A single value, most probably the user forgot the final ','
207
 
            l = [l]
208
 
        return l
209
 
 
210
189
    def gpg_signing_command(self):
211
190
        """What program should be used to sign signatures?"""
212
191
        result = self._gpg_signing_command()
325
304
                path = 'bzr'
326
305
            return path
327
306
 
328
 
    def suppress_warning(self, warning):
329
 
        """Should the warning be suppressed or emitted.
330
 
 
331
 
        :param warning: The name of the warning being tested.
332
 
 
333
 
        :returns: True if the warning should be suppressed, False otherwise.
334
 
        """
335
 
        warnings = self.get_user_option_as_list('suppress_warnings')
336
 
        if warnings is None or warning not in warnings:
337
 
            return False
338
 
        else:
339
 
            return True
340
 
 
341
307
 
342
308
class IniBasedConfig(Config):
343
309
    """A configuration policy that draws from ini files."""
380
346
        """Return the policy for the given (section, option_name) pair."""
381
347
        return POLICY_NONE
382
348
 
383
 
    def _get_change_editor(self):
384
 
        return self.get_user_option('change_editor')
385
 
 
386
349
    def _get_signature_checking(self):
387
350
        """See Config._get_signature_checking."""
388
351
        policy = self._get_user_option('check_signatures')
716
679
 
717
680
        return self._get_best_value('_get_user_id')
718
681
 
719
 
    def _get_change_editor(self):
720
 
        return self._get_best_value('_get_change_editor')
721
 
 
722
682
    def _get_signature_checking(self):
723
683
        """See Config._get_signature_checking."""
724
684
        return self._get_best_value('_get_signature_checking')
866
826
 
867
827
    This doesn't implicitly create it.
868
828
 
869
 
    On Windows it's in the config directory; elsewhere it's /var/crash
870
 
    which may be monitored by apport.  It can be overridden by
871
 
    $APPORT_CRASH_DIR.
 
829
    On Windows it's in the config directory; elsewhere in the XDG cache directory.
872
830
    """
873
831
    if sys.platform == 'win32':
874
832
        return osutils.pathjoin(config_dir(), 'Crash')
875
833
    else:
876
 
        # XXX: hardcoded in apport_python_hook.py; therefore here too -- mbp
877
 
        # 2010-01-31
878
 
        return os.environ.get('APPORT_CRASH_DIR', '/var/crash')
 
834
        return osutils.pathjoin(xdg_cache_dir(), 'crash')
879
835
 
880
836
 
881
837
def xdg_cache_dir():
1501
1457
 
1502
1458
    def _get_config_file(self):
1503
1459
        try:
1504
 
            return StringIO(self._transport.get_bytes(self._filename))
 
1460
            return self._transport.get(self._filename)
1505
1461
        except errors.NoSuchFile:
1506
1462
            return StringIO()
1507
1463