~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
check_signatures=require|ignore|check-available(default)
28
28
create_signatures=always|never|when-required(default)
29
29
gpg_signing_command=name-of-program
 
30
log_format=name-of-format
30
31
 
31
32
in branches.conf, you specify the url of a branch and options for it.
32
33
Wildcards may be used - * and ? as normal in shell completion. Options
49
50
                    gpg signatures, never create them, or create them if the
50
51
                    branch is configured to require them.
51
52
                    NB: This option is planned, but not implemented yet.
 
53
log_format - This options set the default log format.  Options are long, 
 
54
             short, line, or a plugin can register new formats
 
55
 
 
56
In bazaar.conf you can also define aliases in the ALIASES sections, example
 
57
 
 
58
[ALIASES]
 
59
lastlog=log --line -r-10..-1
 
60
ll=log --line -r-10..-1
 
61
h=help
 
62
up=pull
52
63
"""
53
64
 
54
65
 
73
84
class ConfigObj(configobj.ConfigObj):
74
85
 
75
86
    def get_bool(self, section, key):
76
 
        val = self[section][key].lower()
77
 
        if val in ('1', 'yes', 'true', 'on'):
78
 
            return True
79
 
        elif val in ('0', 'no', 'false', 'off'):
80
 
            return False
81
 
        else:
82
 
            raise ValueError("Value %r is not boolean" % val)
 
87
        return self[section].as_bool(key)
83
88
 
84
89
    def get_value(self, section, name):
85
90
        # Try [] for the old DEFAULT section.
120
125
        """See gpg_signing_command()."""
121
126
        return None
122
127
 
 
128
    def log_format(self):
 
129
        """What log format should be used"""
 
130
        result = self._log_format()
 
131
        if result is None:
 
132
            result = "long"
 
133
        return result
 
134
 
 
135
    def _log_format(self):
 
136
        """See log_format()."""
 
137
        return None
 
138
 
123
139
    def __init__(self):
124
140
        super(Config, self).__init__()
125
141
 
183
199
            return True
184
200
        return False
185
201
 
 
202
    def get_alias(self, value):
 
203
        return self._get_alias(value)
 
204
 
 
205
    def _get_alias(self, value):
 
206
        pass
 
207
 
186
208
 
187
209
class IniBasedConfig(Config):
188
210
    """A configuration policy that draws from ini files."""
226
248
        """See Config.gpg_signing_command."""
227
249
        return self._get_user_option('gpg_signing_command')
228
250
 
 
251
    def _log_format(self):
 
252
        """See Config.log_format."""
 
253
        return self._get_user_option('log_format')
 
254
 
229
255
    def __init__(self, get_filename):
230
256
        super(IniBasedConfig, self).__init__()
231
257
        self._get_filename = get_filename
246
272
        raise errors.BzrError("Invalid signatures policy '%s'"
247
273
                              % signature_string)
248
274
 
 
275
    def _get_alias(self, value):
 
276
        try:
 
277
            return self._get_parser().get_value("ALIASES", 
 
278
                                                value)
 
279
        except KeyError:
 
280
            pass
 
281
 
249
282
 
250
283
class GlobalConfig(IniBasedConfig):
251
284
    """The configuration that should be used for a specific location."""
318
351
            return command
319
352
        return self._get_global_config()._gpg_signing_command()
320
353
 
 
354
    def _log_format(self):
 
355
        """See Config.log_format."""
 
356
        command = super(LocationConfig, self)._log_format()
 
357
        if command is not None:
 
358
            return command
 
359
        return self._get_global_config()._log_format()
 
360
 
321
361
    def _get_user_id(self):
322
362
        user_id = super(LocationConfig, self)._get_user_id()
323
363
        if user_id is not None:
409
449
        """See Config.post_commit."""
410
450
        return self._get_location_config()._post_commit()
411
451
 
 
452
    def _log_format(self):
 
453
        """See Config.log_format."""
 
454
        return self._get_location_config()._log_format()
 
455
 
412
456
 
413
457
def ensure_config_dir_exists(path=None):
414
458
    """Make sure a configuration directory exists.
520
564
 
521
565
    def _get_config(self):
522
566
        try:
523
 
            obj = ConfigObj(self.branch.control_files.get('branch.conf'
524
 
                        ).readlines())
525
 
            obj.decode('UTF-8')
 
567
            obj = ConfigObj(self.branch.control_files.get('branch.conf'), 
 
568
                            encoding='utf-8')
526
569
        except errors.NoSuchFile:
527
 
            obj = ConfigObj()
 
570
            obj = ConfigObj(encoding='utf=8')
528
571
        return obj
529
572
 
530
573
    def get_option(self, name, section=None, default=None):
555
598
                    cfg_obj[section] = {}
556
599
                    obj = cfg_obj[section]
557
600
            obj[name] = value
558
 
            cfg_obj.encode('UTF-8')
559
 
            out_file = StringIO(''.join([l+'\n' for l in cfg_obj.write()]))
 
601
            out_file = StringIO()
 
602
            cfg_obj.write(out_file)
560
603
            out_file.seek(0)
561
604
            self.branch.control_files.put('branch.conf', out_file)
562
605
        finally: