~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
 
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')
473
510
        self._write_config_file()
474
511
 
475
512
    def _write_config_file(self):
476
 
        f = open(self._get_filename(), 'wb')
 
513
        path = self._get_filename()
 
514
        f = osutils.open_with_ownership(path, 'wb')
477
515
        self._get_parser().write(f)
478
516
        f.close()
479
517
 
679
717
 
680
718
        return self._get_best_value('_get_user_id')
681
719
 
 
720
    def _get_change_editor(self):
 
721
        return self._get_best_value('_get_change_editor')
 
722
 
682
723
    def _get_signature_checking(self):
683
724
        """See Config._get_signature_checking."""
684
725
        return self._get_best_value('_get_signature_checking')
769
810
                trace.mutter('creating config parent directory: %r', parent_dir)
770
811
            os.mkdir(parent_dir)
771
812
        trace.mutter('creating config directory: %r', path)
772
 
        os.mkdir(path)
 
813
        osutils.mkdir_with_ownership(path)
773
814
 
774
815
 
775
816
def config_dir():
821
862
    return osutils.pathjoin(config_dir(), 'ignore')
822
863
 
823
864
 
 
865
def crash_dir():
 
866
    """Return the directory name to store crash files.
 
867
 
 
868
    This doesn't implicitly create it.
 
869
 
 
870
    On Windows it's in the config directory; elsewhere it's /var/crash
 
871
    which may be monitored by apport.  It can be overridden by
 
872
    $APPORT_CRASH_DIR.
 
873
    """
 
874
    if sys.platform == 'win32':
 
875
        return osutils.pathjoin(config_dir(), 'Crash')
 
876
    else:
 
877
        # XXX: hardcoded in apport_python_hook.py; therefore here too -- mbp
 
878
        # 2010-01-31
 
879
        return os.environ.get('APPORT_CRASH_DIR', '/var/crash')
 
880
 
 
881
 
 
882
def xdg_cache_dir():
 
883
    # See http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
 
884
    # Possibly this should be different on Windows?
 
885
    e = os.environ.get('XDG_CACHE_DIR', None)
 
886
    if e:
 
887
        return e
 
888
    else:
 
889
        return os.path.expanduser('~/.cache')
 
890
 
 
891
 
824
892
def _auto_user_id():
825
893
    """Calculate automatic user identification.
826
894
 
1434
1502
 
1435
1503
    def _get_config_file(self):
1436
1504
        try:
1437
 
            return self._transport.get(self._filename)
 
1505
            return StringIO(self._transport.get_bytes(self._filename))
1438
1506
        except errors.NoSuchFile:
1439
1507
            return StringIO()
1440
1508