From c2a50865f1ea73f43f2d347b2e7595a484f43e78 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 06:33:50 -0500 Subject: [PATCH] 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 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 --- libbe/ui/command_line.py | 29 +++++++++++++++-------------- 1 file 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) -- 2.26.2