~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-09 09:27:46 UTC
  • mto: This revision was merged to the branch mainline in revision 6059.
  • Revision ID: v.ladeuil+lp@free.fr-20110809092746-ly54u54pnykkes8p
Option help is now part of the object itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2274
2274
    value, in which config files it can be stored, etc (TBC).
2275
2275
    """
2276
2276
 
2277
 
    def __init__(self, name, default=None):
 
2277
    def __init__(self, name, default=None, help=None):
2278
2278
        self.name = name
2279
2279
        self.default = default
 
2280
        self.help = help
2280
2281
 
2281
2282
    def get_default(self):
2282
2283
        return self.default
2283
2284
 
2284
2285
 
2285
 
# Options registry
2286
 
 
2287
 
option_registry = registry.Registry()
 
2286
class OptionRegistry(registry.Registry):
 
2287
    """Register config options by their name.
 
2288
 
 
2289
    This overrides ``registry.Registry`` to simplify registration by acquiring
 
2290
    some informations from the option object itself.
 
2291
    """
 
2292
 
 
2293
    def register(self, option):
 
2294
        """Register a new option to its name.
 
2295
 
 
2296
        :param option: The option to register. Its name is used as the key.
 
2297
        """
 
2298
        super(OptionRegistry, self).register(option.name, option,
 
2299
                                             help=option.help)
 
2300
 
 
2301
    def register_lazy(self, key, module_name, member_name):
 
2302
        """Register a new option to be loaded on request.
 
2303
 
 
2304
        :param key: This is the key to use to request the option later. Since
 
2305
            the registration is lazy, it should be provided and match the
 
2306
            option name.
 
2307
 
 
2308
        :param module_name: The python path to the module. Such as 'os.path'.
 
2309
 
 
2310
        :param member_name: The member of the module to return.  If empty or
 
2311
                None, get() will return the module itself.
 
2312
        """
 
2313
        super(OptionRegistry, self).register_lazy(key,
 
2314
                                                  module_name, member_name)
 
2315
 
 
2316
    def get_help(self, key=None):
 
2317
        """Get the help text associated with the given key"""
 
2318
        option = self.get(key)
 
2319
        the_help = option.help
 
2320
        if callable(the_help):
 
2321
            return the_help(self, key)
 
2322
        return the_help
 
2323
 
 
2324
 
 
2325
 
 
2326
 
 
2327
option_registry = OptionRegistry()
2288
2328
 
2289
2329
 
2290
2330
# Registered options in lexicographical order
2291
2331
 
2292
2332
option_registry.register(
2293
 
    'dirstate.fdatasync', Option('dirstate.fdatasync', default=True),
2294
 
    help='Flush dirstate changes onto physical disk?')
2295
 
option_registry.register(
2296
 
    'default_format', Option('default_format', default='2a'),
2297
 
    help='Format used when creating branches.')
2298
 
option_registry.register(
2299
 
    'editor', Option('editor'),
2300
 
    help='The command called to launch an editor to enter a message.')
2301
 
option_registry.register(
2302
 
    'language', Option('language'),
2303
 
    help='Language to translate messages into.')
2304
 
option_registry.register(
2305
 
    'output_encoding', Option('output_encoding'),
2306
 
    help='Unicode encoding for output (terminal encoding if not specified).')
2307
 
option_registry.register(
2308
 
    'repository.fdatasync',
2309
 
    Option('repository.fdatasync', default=True),
2310
 
    help='Flush repository changes onto physical disk?')
 
2333
    Option('dirstate.fdatasync', default=True,
 
2334
           help='''
 
2335
Flush dirstate changes onto physical disk?
 
2336
 
 
2337
If true (default), working tree metadata changes are flushed through the
 
2338
OS buffers to physical disk.  This is somewhat slower, but means data
 
2339
should not be lost if the machine crashes.  See also repository.fdatasync.
 
2340
'''))
 
2341
option_registry.register(
 
2342
    Option('default_format', default='2a',
 
2343
           help='Format used when creating branches.'))
 
2344
option_registry.register(
 
2345
    Option('editor',
 
2346
           help='The command called to launch an editor to enter a message.'))
 
2347
option_registry.register(
 
2348
    Option('language',
 
2349
           help='Language to translate messages into.'))
 
2350
option_registry.register(
 
2351
    Option('output_encoding',
 
2352
           help= 'Unicode encoding for output'
 
2353
           ' (terminal encoding if not specified).'))
 
2354
option_registry.register(
 
2355
    Option('repository.fdatasync', default=True,
 
2356
           help='''\
 
2357
Flush repository changes onto physical disk?
 
2358
 
 
2359
If true (default), repository changes are flushed through the OS buffers
 
2360
to physical disk.  This is somewhat slower, but means data should not be
 
2361
lost if the machine crashes.  See also dirstate.fdatasync.
 
2362
'''))
2311
2363
 
2312
2364
 
2313
2365
class Section(object):