32
31
each revision specifier supplied.
34
33
>>> _parse_revision_str('234')
35
[<RevisionSpec_revno 234>]
34
[<RevisionSpec_int 234>]
36
35
>>> _parse_revision_str('234..567')
37
[<RevisionSpec_revno 234>, <RevisionSpec_revno 567>]
36
[<RevisionSpec_int 234>, <RevisionSpec_int 567>]
38
37
>>> _parse_revision_str('..')
39
38
[<RevisionSpec None>, <RevisionSpec None>]
40
39
>>> _parse_revision_str('..234')
41
[<RevisionSpec None>, <RevisionSpec_revno 234>]
40
[<RevisionSpec None>, <RevisionSpec_int 234>]
42
41
>>> _parse_revision_str('234..')
43
[<RevisionSpec_revno 234>, <RevisionSpec None>]
42
[<RevisionSpec_int 234>, <RevisionSpec None>]
44
43
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
45
[<RevisionSpec_revno 234>, <RevisionSpec_revno 456>, <RevisionSpec_revno 789>]
44
[<RevisionSpec_int 234>, <RevisionSpec_int 456>, <RevisionSpec_int 789>]
46
45
>>> _parse_revision_str('234....789') #Error ?
47
[<RevisionSpec_revno 234>, <RevisionSpec None>, <RevisionSpec_revno 789>]
46
[<RevisionSpec_int 234>, <RevisionSpec None>, <RevisionSpec_int 789>]
48
47
>>> _parse_revision_str('revid:test@other.com-234234')
49
48
[<RevisionSpec_revid revid:test@other.com-234234>]
50
49
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
51
50
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
52
51
>>> _parse_revision_str('revid:test@other.com-234234..23')
53
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revno 23>]
52
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_int 23>]
54
53
>>> _parse_revision_str('date:2005-04-12')
55
54
[<RevisionSpec_date date:2005-04-12>]
56
55
>>> _parse_revision_str('date:2005-04-12 12:24:33')
60
59
>>> _parse_revision_str('date:2005-04-12,12:24:33')
61
60
[<RevisionSpec_date date:2005-04-12,12:24:33>]
62
61
>>> _parse_revision_str('-5..23')
63
[<RevisionSpec_revno -5>, <RevisionSpec_revno 23>]
62
[<RevisionSpec_int -5>, <RevisionSpec_int 23>]
64
63
>>> _parse_revision_str('-5')
65
[<RevisionSpec_revno -5>]
64
[<RevisionSpec_int -5>]
66
65
>>> _parse_revision_str('123a')
67
66
Traceback (most recent call last):
69
NoSuchRevisionSpec: No namespace registered for string: '123a'
68
BzrError: No namespace registered for string: '123a'
70
69
>>> _parse_revision_str('abc')
71
70
Traceback (most recent call last):
73
NoSuchRevisionSpec: No namespace registered for string: 'abc'
72
BzrError: No namespace registered for string: 'abc'
74
73
>>> _parse_revision_str('branch:../branch2')
75
74
[<RevisionSpec_branch branch:../branch2>]
76
75
>>> _parse_revision_str('branch:../../branch2')
77
76
[<RevisionSpec_branch branch:../../branch2>]
78
77
>>> _parse_revision_str('branch:../../branch2..23')
79
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_revno 23>]
78
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_int 23>]
81
80
# TODO: Maybe move this into revisionspec.py
81
old_format_re = re.compile('\d*:\d*')
82
m = old_format_re.match(revstr)
83
sep = re.compile("\\.\\.(?!/)")
84
for x in sep.split(revstr):
85
revs.append(RevisionSpec.from_string(x or None))
85
warning('Colon separator for revision numbers is deprecated.'
87
for rev in revstr.split(':'):
89
revs.append(RevisionSpec(int(rev)))
91
revs.append(RevisionSpec(None))
93
sep = re.compile("\\.\\.(?!/)")
94
for x in sep.split(revstr):
95
revs.append(RevisionSpec(x or None))
143
153
if option is self:
146
def get_negation_name(self):
147
if self.name.startswith('no-'):
150
return 'no-' + self.name
152
def add_option(self, parser, short_name):
153
"""Add this option to an Optparse parser"""
154
option_strings = ['--%s' % self.name]
155
if short_name is not None:
156
option_strings.append('-%s' % short_name)
159
parser.add_option(action='store_true', dest=self.name,
161
default=OptionParser.DEFAULT_VALUE,
163
negation_strings = ['--%s' % self.get_negation_name()]
164
parser.add_option(action='store_false', dest=self.name,
165
help=optparse.SUPPRESS_HELP, *negation_strings)
167
parser.add_option(action='callback',
168
callback=self._optparse_callback,
169
type='string', metavar=self.argname.upper(),
171
default=OptionParser.DEFAULT_VALUE,
174
def _optparse_callback(self, option, opt, value, parser):
175
setattr(parser.values, self.name, self.type(value))
177
def iter_switches(self):
178
"""Iterate through the list of switches provided by the option
180
:return: an iterator of (name, short_name, argname, help)
182
argname = self.argname
183
if argname is not None:
184
argname = argname.upper()
185
yield self.name, self.short_name(), argname, self.help
188
class OptionParser(optparse.OptionParser):
189
"""OptionParser that raises exceptions instead of exiting"""
191
DEFAULT_VALUE = object()
193
def error(self, message):
194
raise BzrCommandError(message)
197
def get_optparser(options):
198
"""Generate an optparse parser for bzrlib-style options"""
200
parser = OptionParser()
201
parser.remove_option('--help')
202
short_options = dict((k.name, v) for v, k in
203
Option.SHORT_OPTIONS.iteritems())
204
for option in options.itervalues():
205
option.add_option(parser, short_options.get(option.name))
209
157
def _global_option(name, **kwargs):
210
158
"""Register o as a global option."""