~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/option.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-14 20:47:17 UTC
  • mto: (2353.4.2 locking)
  • mto: This revision was merged to the branch mainline in revision 2360.
  • Revision ID: john@arbash-meinel.com-20070314204717-htynwogv97fqr22a
Cleanup errors, and change ReadOnlyLockError to pass around more details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
152
152
    def short_name(self):
153
153
        if self._short_name:
154
154
            return self._short_name
 
155
        else:
 
156
            # remove this when SHORT_OPTIONS is removed
 
157
            # XXX: This is accessing a DeprecatedDict, so we call the super 
 
158
            # method to avoid warnings
 
159
            for (k, v) in dict.iteritems(Option.SHORT_OPTIONS):
 
160
                if v == self:
 
161
                    return k
155
162
 
156
163
    def set_short_name(self, short_name):
157
164
        self._short_name = short_name
198
205
        yield self.name, self.short_name(), argname, self.help
199
206
 
200
207
 
201
 
class ListOption(Option):
202
 
    """Option used to provide a list of values.
203
 
 
204
 
    On the command line, arguments are specified by a repeated use of the
205
 
    option. '-' is a special argument that resets the list. For example,
206
 
      --foo=a --foo=b
207
 
    sets the value of the 'foo' option to ['a', 'b'], and
208
 
      --foo=a --foo=b --foo=- --foo=c
209
 
    sets the value of the 'foo' option to ['c'].
210
 
    """
211
 
 
212
 
    def add_option(self, parser, short_name):
213
 
        """Add this option to an Optparse parser."""
214
 
        option_strings = ['--%s' % self.name]
215
 
        if short_name is not None:
216
 
            option_strings.append('-%s' % short_name)
217
 
        parser.add_option(action='callback',
218
 
                          callback=self._optparse_callback,
219
 
                          type='string', metavar=self.argname.upper(),
220
 
                          help=self.help, default=[],
221
 
                          *option_strings)
222
 
 
223
 
    def _optparse_callback(self, option, opt, value, parser):
224
 
        values = getattr(parser.values, self.name)
225
 
        if value == '-':
226
 
            del values[:]
227
 
        else:
228
 
            values.append(self.type(value))
229
 
 
230
 
 
231
208
class RegistryOption(Option):
232
209
    """Option based on a registry
233
210
 
300
277
        if self.value_switches:
301
278
            for key in self.registry.keys():
302
279
                option_strings = ['--%s' % key]
303
 
                if getattr(self.registry.get_info(key), 'hidden', False):
304
 
                    help = optparse.SUPPRESS_HELP
305
 
                else:
306
 
                    help = self.registry.get_help(key)
307
280
                parser.add_option(action='callback',
308
281
                              callback=self._optparse_value_callback(key),
309
 
                                  help=help,
 
282
                                  help=self.registry.get_help(key),
310
283
                                  *option_strings)
311
284
 
312
285
    def _optparse_value_callback(self, cb_value):
369
342
 
370
343
_global_option('all')
371
344
_global_option('overwrite', help='Ignore differences between branches and '
372
 
               'overwrite unconditionally.')
 
345
               'overwrite unconditionally')
373
346
_global_option('basis', type=str)
374
347
_global_option('bound')
375
348
_global_option('diff-options', type=str)
 
349
_global_option('help',
 
350
               help='show help message',
 
351
               short_name='h')
376
352
_global_option('file', type=unicode, short_name='F')
377
353
_global_option('force')
378
354
_global_option('format', type=unicode)
379
355
_global_option('forward')
380
356
_global_option('message', type=unicode,
381
 
               short_name='m',
382
 
               help='Message string.')
 
357
               short_name='m')
383
358
_global_option('no-recurse')
384
359
_global_option('profile',
385
 
               help='Show performance profiling information.')
 
360
               help='show performance profiling information')
386
361
_global_option('revision',
387
362
               type=_parse_revision_str,
388
363
               short_name='r',
389
 
               help='See \'help revisionspec\' for details.')
390
 
_global_option('show-ids',
391
 
               help='Show internal object ids.')
 
364
               help='See \'help revisionspec\' for details')
 
365
_global_option('show-ids', 
 
366
               help='show internal object ids')
392
367
_global_option('timezone', 
393
368
               type=str,
394
369
               help='display timezone as local, original, or utc')
395
370
_global_option('unbound')
396
371
_global_option('verbose',
397
 
               help='Display more information.',
 
372
               help='display more information',
398
373
               short_name='v')
399
374
_global_option('version')
400
375
_global_option('email')
401
376
_global_option('update')
402
 
_global_registry_option('log-format', "Use specified log format.",
 
377
_global_registry_option('log-format', "Use this log format",
403
378
                        log.log_formatter_registry, value_switches=True,
404
379
                        title='Log format')
405
380
_global_option('long', help='Use detailed log format. Same as --log-format long',
408
383
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
409
384
_global_option('root', type=str)
410
385
_global_option('no-backup')
411
 
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
 
386
_global_registry_option('merge-type', 'Select a particular merge algorithm',
412
387
                        _merge_type_registry, value_switches=True,
413
388
                        title='Merge algorithm')
414
389
_global_option('pattern', type=str)
415
390
_global_option('quiet', short_name='q')
416
391
_global_option('remember', help='Remember the specified location as a'
417
392
               ' default.')
418
 
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
 
393
_global_option('reprocess', help='Reprocess to reduce spurious conflicts')
419
394
_global_option('kind', type=str)
420
395
_global_option('dry-run',
421
 
               help="Show what would be done, but don't actually do anything.")
 
396
               help="show what would be done, but don't actually do anything")
422
397
_global_option('name-from-revision', help='The path name in the old tree.')
423
398
 
424
 
_help_option = Option('help',
425
 
                      help='Show help message.',
426
 
                      short_name='h')
 
399
 
 
400
# prior to 0.14 these were always globally registered; the old dict is
 
401
# available for plugins that use it but it should not be used.
 
402
Option.SHORT_OPTIONS = symbol_versioning.DeprecatedDict(
 
403
    symbol_versioning.zero_fourteen,
 
404
    'SHORT_OPTIONS',
 
405
    {
 
406
        'F': Option.OPTIONS['file'],
 
407
        'h': Option.OPTIONS['help'],
 
408
        'm': Option.OPTIONS['message'],
 
409
        'r': Option.OPTIONS['revision'],
 
410
        'v': Option.OPTIONS['verbose'],
 
411
        'l': Option.OPTIONS['long'],
 
412
        'q': Option.OPTIONS['quiet'],
 
413
    },
 
414
    'Set the short option name when constructing the Option.',
 
415
    )