~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
156
165
    def get_mail_client(self):
157
166
        """Get a mail client to use"""
158
167
        selected_client = self.get_user_option('mail_client')
181
190
        """Get a generic option as a boolean - no special process, no default.
182
191
 
183
192
        :return None if the option doesn't exist or its value can't be
184
 
            interpreted as a boolean. Returns True or False ortherwise.
 
193
            interpreted as a boolean. Returns True or False otherwise.
185
194
        """
186
195
        s = self._get_user_option(option_name)
187
196
        return ui.bool_from_string(s)
188
197
 
 
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
 
189
210
    def gpg_signing_command(self):
190
211
        """What program should be used to sign signatures?"""
191
212
        result = self._gpg_signing_command()
304
325
                path = 'bzr'
305
326
            return path
306
327
 
 
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
 
307
341
 
308
342
class IniBasedConfig(Config):
309
343
    """A configuration policy that draws from ini files."""
346
380
        """Return the policy for the given (section, option_name) pair."""
347
381
        return POLICY_NONE
348
382
 
 
383
    def _get_change_editor(self):
 
384
        return self.get_user_option('change_editor')
 
385
 
349
386
    def _get_signature_checking(self):
350
387
        """See Config._get_signature_checking."""
351
388
        policy = self._get_user_option('check_signatures')
679
716
 
680
717
        return self._get_best_value('_get_user_id')
681
718
 
 
719
    def _get_change_editor(self):
 
720
        return self._get_best_value('_get_change_editor')
 
721
 
682
722
    def _get_signature_checking(self):
683
723
        """See Config._get_signature_checking."""
684
724
        return self._get_best_value('_get_signature_checking')
821
861
    return osutils.pathjoin(config_dir(), 'ignore')
822
862
 
823
863
 
 
864
def crash_dir():
 
865
    """Return the directory name to store crash files.
 
866
 
 
867
    This doesn't implicitly create it.
 
868
 
 
869
    On Windows it's in the config directory; elsewhere in the XDG cache directory.
 
870
    """
 
871
    if sys.platform == 'win32':
 
872
        return osutils.pathjoin(config_dir(), 'Crash')
 
873
    else:
 
874
        return osutils.pathjoin(xdg_cache_dir(), 'crash')
 
875
 
 
876
 
 
877
def xdg_cache_dir():
 
878
    # See http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
 
879
    # Possibly this should be different on Windows?
 
880
    e = os.environ.get('XDG_CACHE_DIR', None)
 
881
    if e:
 
882
        return e
 
883
    else:
 
884
        return os.path.expanduser('~/.cache')
 
885
 
 
886
 
824
887
def _auto_user_id():
825
888
    """Calculate automatic user identification.
826
889
 
1434
1497
 
1435
1498
    def _get_config_file(self):
1436
1499
        try:
1437
 
            return self._transport.get(self._filename)
 
1500
            return StringIO(self._transport.get_bytes(self._filename))
1438
1501
        except errors.NoSuchFile:
1439
1502
            return StringIO()
1440
1503