/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import optparse
23
23
import re
24
24
 
25
 
from . import (
 
25
from bzrlib.lazy_import import lazy_import
 
26
lazy_import(globals(), """
 
27
from bzrlib import (
26
28
    errors,
 
29
    revisionspec,
 
30
    i18n,
 
31
    )
 
32
""")
 
33
 
 
34
from bzrlib import (
27
35
    registry as _mod_registry,
28
 
    revisionspec,
29
 
    )
30
 
from .sixish import (
31
 
    text_type,
32
 
    viewitems,
33
 
    )
34
 
 
35
 
 
36
 
class BadOptionValue(errors.BzrError):
37
 
 
38
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
39
 
 
40
 
    def __init__(self, name, value):
41
 
        errors.BzrError.__init__(self, name=name, value=value)
 
36
    )
42
37
 
43
38
 
44
39
def _parse_revision_str(revstr):
131
126
        return merge_types[typestring][0]
132
127
    except KeyError:
133
128
        templ = '%s%%7s: %%s' % (' '*12)
134
 
        lines = [templ % (f[0], f[1][1]) for f in merge_types.items()]
 
129
        lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
135
130
        type_list = '\n'.join(lines)
136
131
        msg = "No known merge type %s. Supported types are:\n%s" %\
137
132
            (typestring, type_list)
308
303
    def validate_value(self, value):
309
304
        """Validate a value name"""
310
305
        if value not in self.registry:
311
 
            raise BadOptionValue(self.name, value)
 
306
            raise errors.BadOptionValue(self.name, value)
312
307
 
313
308
    def convert(self, value):
314
309
        """Convert a value name into an output type"""
393
388
        if self.enum_switch:
394
389
            Option.add_option(self, parser, short_name)
395
390
        if self.value_switches:
396
 
            alias_map = self.registry.alias_map()
397
391
            for key in self.registry.keys():
398
 
                if key in self.registry.aliases():
399
 
                    continue
400
 
                option_strings = [
401
 
                    ('--%s' % name)
402
 
                    for name in [key] +
403
 
                    [alias for alias in alias_map.get(key, [])
404
 
                        if not self.is_hidden(alias)]]
 
392
                option_strings = ['--%s' % key]
405
393
                if self.is_hidden(key):
406
394
                    help = optparse.SUPPRESS_HELP
407
395
                else:
434
422
            for key in sorted(self.registry.keys()):
435
423
                yield key, None, None, self.registry.get_help(key)
436
424
 
437
 
    def is_alias(self, name):
438
 
        """Check whether a particular format is an alias."""
439
 
        if name == self.name:
440
 
            return False
441
 
        return name in self.registry.aliases()
442
 
 
443
425
    def is_hidden(self, name):
444
426
        if name == self.name:
445
427
            return Option.is_hidden(self, name)
467
449
    def format_option(self, option):
468
450
        """code taken from Python's optparse.py"""
469
451
        if option.help:
470
 
            from .i18n import gettext
471
 
            option.help = gettext(option.help)
 
452
            option.help = i18n.gettext(option.help)
472
453
        return optparse.IndentedHelpFormatter.format_option(self, option)
473
454
 
474
455
 
475
456
def get_optparser(options):
476
 
    """Generate an optparse parser for breezy-style options"""
 
457
    """Generate an optparse parser for bzrlib-style options"""
477
458
 
478
459
    parser = OptionParser()
479
460
    parser.remove_option('--help')
480
 
    for option in options.values():
 
461
    for option in options.itervalues():
481
462
        option.add_option(parser, option.short_name())
482
463
    return parser
483
464
 
558
539
               short_name='c',
559
540
               param_name='revision',
560
541
               help='Select changes introduced by the specified revision. See also "help revisionspec".')
561
 
_global_option('directory', short_name='d', type=text_type,
 
542
_global_option('directory', short_name='d', type=unicode,
562
543
               help='Branch to operate on, instead of working directory.')
563
 
_global_option('file', type=text_type, short_name='F')
 
544
_global_option('file', type=unicode, short_name='F')
564
545
_global_registry_option('log-format', "Use specified log format.",
565
 
                        lazy_registry=('breezy.log', 'log_formatter_registry'),
 
546
                        lazy_registry=('bzrlib.log', 'log_formatter_registry'),
566
547
                        value_switches=True, title='Log format',
567
548
                        short_value_switches={'short': 'S'})
568
549
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
569
 
                        lazy_registry=('breezy.merge', 'merge_type_registry'),
 
550
                        lazy_registry=('bzrlib.merge', 'merge_type_registry'),
570
551
                        value_switches=True, title='Merge algorithm')
571
 
_global_option('message', type=text_type,
 
552
_global_option('message', type=unicode,
572
553
               short_name='m',
573
554
               help='Message string.')
574
555
_global_option('null', short_name='0',