/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: Vincent Ladeuil
  • Date: 2008-10-02 13:25:47 UTC
  • mfrom: (3759 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3760.
  • Revision ID: v.ladeuil+lp@free.fr-20081002132547-txs4fs006e9p0gt1
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
""")
30
30
 
31
31
from bzrlib import (
32
 
    log,
33
 
    registry,
 
32
    registry as _mod_registry,
34
33
    )
35
34
 
 
35
 
36
36
def _parse_revision_str(revstr):
37
37
    """This handles a revision string -> revno.
38
38
 
306
306
        else:
307
307
            return self.converter(value)
308
308
 
309
 
    def __init__(self, name, help, registry, converter=None,
310
 
        value_switches=False, title=None, enum_switch=True):
 
309
    def __init__(self, name, help, registry=None, converter=None,
 
310
        value_switches=False, title=None, enum_switch=True,
 
311
        lazy_registry=None):
311
312
        """
312
313
        Constructor.
313
314
 
321
322
            '--knit' can be used interchangeably.
322
323
        :param enum_switch: If true, a switch is provided with the option name,
323
324
            which takes a value.
 
325
        :param lazy_registry: A tuple of (module name, attribute name) for a
 
326
            registry to be lazily loaded.
324
327
        """
325
328
        Option.__init__(self, name, help, type=self.convert)
326
 
        self.registry = registry
 
329
        self._registry = registry
 
330
        if registry is None:
 
331
            if lazy_registry is None:
 
332
                raise AssertionError(
 
333
                    'One of registry or lazy_registry must be given.')
 
334
            self._lazy_registry = _mod_registry._LazyObjectGetter(
 
335
                *lazy_registry)
 
336
        if registry is not None and lazy_registry is not None:
 
337
            raise AssertionError(
 
338
                'registry and lazy_registry are mutually exclusive')
327
339
        self.name = name
328
340
        self.converter = converter
329
341
        self.value_switches = value_switches
332
344
        if self.title is None:
333
345
            self.title = name
334
346
 
 
347
    @property
 
348
    def registry(self):
 
349
        if self._registry is None:
 
350
            self._registry = self._lazy_registry.get_obj()
 
351
        return self._registry
 
352
    
335
353
    @staticmethod
336
354
    def from_kwargs(name_, help=None, title=None, value_switches=False,
337
355
                    enum_switch=True, **kwargs):
341
359
        RegistryOption constructor.  Any other keyword arguments are treated
342
360
        as values for the option, and they value is treated as the help.
343
361
        """
344
 
        reg = registry.Registry()
 
362
        reg = _mod_registry.Registry()
345
363
        for name, switch_help in kwargs.iteritems():
346
364
            name = name.replace('_', '-')
347
365
            reg.register(name, name, help=switch_help)
434
452
    Option.OPTIONS[name] = Option(name, **kwargs)
435
453
 
436
454
 
437
 
def _global_registry_option(name, help, registry, **kwargs):
 
455
def _global_registry_option(name, help, registry=None, **kwargs):
438
456
    Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
439
457
 
440
458
 
441
 
class MergeTypeRegistry(registry.Registry):
442
 
 
443
 
    pass
444
 
 
445
 
 
446
459
# This is the verbosity level detected during command line parsing.
447
460
# Note that the final value is dependent on the order in which the
448
461
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
471
484
            _verbosity_level = -1
472
485
 
473
486
 
 
487
class MergeTypeRegistry(_mod_registry.Registry):
 
488
 
 
489
    pass
 
490
 
 
491
 
474
492
_merge_type_registry = MergeTypeRegistry()
475
493
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
476
494
                                   "Native diff3-style merge")
519
537
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
520
538
_global_option('show-ids',
521
539
               help='Show internal object ids.')
522
 
_global_option('timezone', 
 
540
_global_option('timezone',
523
541
               type=str,
524
 
               help='display timezone as local, original, or utc')
 
542
               help='Display timezone as local, original, or utc.')
525
543
_global_option('unbound')
526
544
_global_option('version')
527
545
_global_option('email')
528
546
_global_option('update')
529
547
_global_registry_option('log-format', "Use specified log format.",
530
 
                        log.log_formatter_registry, value_switches=True,
531
 
                        title='Log format')
 
548
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
 
549
                        value_switches=True, title='Log format')
532
550
_global_option('long', help='Use detailed log format. Same as --log-format long',
533
551
               short_name='l')
534
552
_global_option('short', help='Use moderately short log format. Same as --log-format short')