/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 06:18:42 UTC
  • mfrom: (3757 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3759.
  • Revision ID: v.ladeuil+lp@free.fr-20081002061842-4ctag1pkr7ua9gu2
Fix conflict. Related to moved lines, nice use case

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
 
466
484
            _verbosity_level = -1
467
485
 
468
486
 
469
 
class MergeTypeRegistry(registry.Registry):
 
487
class MergeTypeRegistry(_mod_registry.Registry):
470
488
 
471
489
    pass
472
490
 
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')