~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

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."""
195
217
        else:
196
218
            input = file
197
219
        try:
198
 
            self._parser = ConfigObj(input)
199
 
            dec = getattr(self._parser, 'decode', None)
200
 
            if dec is not None:
201
 
                dec('UTF-8')
 
220
            self._parser = ConfigObj(input, encoding='utf-8')
202
221
        except configobj.ConfigObjError, e:
203
222
            raise errors.ParseConfigError(e.errors, e.config.filename)
204
223
        return self._parser
229
248
        """See Config.gpg_signing_command."""
230
249
        return self._get_user_option('gpg_signing_command')
231
250
 
 
251
    def _log_format(self):
 
252
        """See Config.log_format."""
 
253
        return self._get_user_option('log_format')
 
254
 
232
255
    def __init__(self, get_filename):
233
256
        super(IniBasedConfig, self).__init__()
234
257
        self._get_filename = get_filename
249
272
        raise errors.BzrError("Invalid signatures policy '%s'"
250
273
                              % signature_string)
251
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
 
252
282
 
253
283
class GlobalConfig(IniBasedConfig):
254
284
    """The configuration that should be used for a specific location."""
304
334
            # if path is longer, and recurse is not true, no match
305
335
            if len(section_names) < len(location_names):
306
336
                try:
307
 
                    if not self._get_parser().get_bool(section, 'recurse'):
 
337
                    if not self._get_parser()[section].as_bool('recurse'):
308
338
                        continue
309
339
                except KeyError:
310
340
                    pass
321
351
            return command
322
352
        return self._get_global_config()._gpg_signing_command()
323
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
 
324
361
    def _get_user_id(self):
325
362
        user_id = super(LocationConfig, self)._get_user_id()
326
363
        if user_id is not None:
415
452
        """See Config.post_commit."""
416
453
        return self._get_location_config()._post_commit()
417
454
 
 
455
    def _log_format(self):
 
456
        """See Config.log_format."""
 
457
        return self._get_location_config()._log_format()
 
458
 
418
459
 
419
460
def ensure_config_dir_exists(path=None):
420
461
    """Make sure a configuration directory exists.
527
568
 
528
569
    def _get_config(self):
529
570
        try:
530
 
            obj = ConfigObj(self.branch.control_files.get('branch.conf'
531
 
                        ).readlines())
532
 
            obj.decode('UTF-8')
 
571
            obj = ConfigObj(self.branch.control_files.get('branch.conf'), 
 
572
                            encoding='utf-8')
533
573
        except errors.NoSuchFile:
534
 
            obj = ConfigObj()
 
574
            obj = ConfigObj(encoding='utf=8')
535
575
        return obj
536
576
 
537
577
    def get_option(self, name, section=None, default=None):
562
602
                    cfg_obj[section] = {}
563
603
                    obj = cfg_obj[section]
564
604
            obj[name] = value
565
 
            cfg_obj.encode('UTF-8')
566
 
            out_file = StringIO(''.join([l+'\n' for l in cfg_obj.write()]))
 
605
            out_file = StringIO()
 
606
            cfg_obj.write(out_file)
567
607
            out_file.seek(0)
568
608
            self.branch.control_files.put('branch.conf', out_file)
569
609
        finally: