aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-13 06:33:50 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-13 06:33:50 -0500
commitc2a50865f1ea73f43f2d347b2e7595a484f43e78 (patch)
tree146c8d5c78da986fa1143348851b6fc8dc33d4ae /libbe
parent4d057dab603f42ec40b911dbee6792dcf107bd14 (diff)
downloadbugseverywhere-c2a50865f1ea73f43f2d347b2e7595a484f43e78.tar.gz
Rearrange libbe.ui.command_line.CmdOptionParser._add_option() for Python 2.5
Python 2.6 doesn't mind, but 2.5 doesn't like kwargs after a * expansion: $ ./be list Traceback (most recent call last): File "./be", line 5, in <module> import libbe.ui.command_line File "/home/wking/src/fun/be/be.restructure/libbe/ui/command_line.py", line 63 *opt_strings, action='callback', dest=dest, ^ SyntaxError: invalid syntax
Diffstat (limited to 'libbe')
-rwxr-xr-xlibbe/ui/command_line.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/libbe/ui/command_line.py b/libbe/ui/command_line.py
index b0b52af..60741f5 100755
--- a/libbe/ui/command_line.py
+++ b/libbe/ui/command_line.py
@@ -52,27 +52,28 @@ class CmdOptionParser(optparse.OptionParser):
def _add_option(self, option):
option.validate()
self._option_by_name[option.name] = option
- opt_strings = ['--'+option.name]
- dest = option.name.replace('-', '_')
+ long_opt = '--%s' % option.name
+ if option.short_name != None:
+ short_opt = '-%s' % option.short_name
assert '_' not in option.name, \
'Non-reconstructable option name %s' % option.name
- if option.short_name != None:
- opt_strings.append('-'+option.short_name)
+ kwargs = {'dest':option.name.replace('-', '_'),
+ 'help':option.help}
if option.arg == None: # a callback option
- opt = optparse.Option(
- *opt_strings, action='callback', dest=dest,
- callback=self.callback, help=option.help)
+ kwargs['action'] = 'callback'
+ kwargs['callback'] = self.callback
else:
- kwargs = {}
if option.arg.type == 'bool':
- action = 'store_true'
+ kwargs['action'] = 'store_true'
else:
kwargs['type'] = option.arg.type
- action = 'store'
- opt = optparse.Option(
- *opt_strings, metavar=option.arg.metavar,
- default=option.arg.default, action=action,
- dest=dest, help=option.help, **kwargs)
+ kwargs['action'] = 'store'
+ kwargs['metavar'] = option.arg.metavar
+ kwargs['default'] = option.arg.default
+ if option.short_name != None:
+ opt = optparse.Option(short_opt, long_opt, **kwargs)
+ else:
+ opt = optparse.Option(long_opt, **kwargs)
opt._option = option
self.add_option(opt)