~ubuntu-branches/ubuntu/lucid/bzr/lucid-proposed

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2006-03-20 08:31:00 UTC
  • mfrom: (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060320083100-ovdi2ssuw0epcx8s
Tags: 0.8~200603200831-0ubuntu1
* Snapshot uploaded to Dapper at Martin Pool's request.

* Disable testsuite for upload.  Fakeroot and the testsuite don't
  play along.

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:
379
419
        This is looked up in the email controlfile for the branch.
380
420
        """
381
421
        try:
382
 
            return (self.branch.controlfile("email", "r") 
 
422
            return (self.branch.control_files.get_utf8("email") 
383
423
                    .read()
384
424
                    .decode(bzrlib.user_encoding)
385
425
                    .rstrip("\r\n"))
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.controlfile('branch.conf',
524
 
                                                    'rb').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
 
            self.branch.put_controlfile('branch.conf', out_file, encode=False)
 
604
            self.branch.control_files.put('branch.conf', out_file)
562
605
        finally:
563
606
            self.branch.unlock()