self._run(inqueue, outqueue, params)
except CommandExit, e:
if isinstance(e, Failure):
- outqueue.put(e.message)
+ outqueue.put(str(e))
outqueue.put(e)
return 1
outqueue.put(e)
for argument in self.arguments:
names = [argument.name] + argument.aliases
settings = [(name,v) for name,v in params.items() if name in names]
- if len(settings) == 0:
+ num_provided = len(settings)
+ if num_provided == 0:
if argument.optional == True or argument.count == 0:
settings = [(argument.name, argument.default)]
else:
raise Failure('Required argument %s not set.'
% argument.name)
- if len(settings) > 1:
+ if num_provided > 1:
raise Failure('Multiple settings for %s:\n %s'
% (argument.name,
'\n '.join(['%s: %s' % (name,value)
params.remove(name)
params[argument.name] = value
if argument.callback != None:
- value = argument.callback(self, argument, value)
+ if num_provided > 0:
+ value = argument.callback(self, argument, value)
params[argument.name] = value
argument.validate(value)
return params
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
i_min = min([p.index for p in params['points']])
i_max = max([p.index for p in params['points']])
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].next()
class PreviousCommand (Command):
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].previous()
class JumpCommand (Command):
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].jump(params['index'])
class SaveCommand (Command):
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].save(params['output'])
class LoadCommand (Command):
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
p = FilePlaylist(drivers=params['drivers'], path=params['input'])
p.load()
outqueue.put(p)
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].append_curve_by_path(params['input'],
params['info'])
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
for path in sorted(glob.glob(params['input'])):
params['playlist'].append_curve_by_path(path, params['info'])
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
params['playlist'].pop(params['index'])
params['playlist'].jump(params._index)
],
help=self.__doc__)
- def _run(inqueue, outqueue, params):
+ def _run(self, inqueue, outqueue, params):
p = params['playlist'].filter(params['filter'])
outqueue.put(p)
import cmd
import optparse
import readline # including readline makes cmd.Cmd.cmdloop() smarter
+import shlex
from ..command import CommandExit, Command, Argument
from ..ui import UserInterface, CommandMessage
def command_parser(command):
p = optparse.OptionParser()
+ opts = []
args = []
for a in command.arguments:
if a.name == 'help':
continue # 'help' is a default OptionParser option
+ name = a.name.replace('_', '-')
if a.optional == True:
- p.add_option(
- '--%s' % a.name.replace('_', '-'),
- dest=a.name, default=a.default)
+ p.add_option('--%s' % name, dest=a.name, default=a.default)
+ opts.append((name, a))
else:
- args.append((a.name.replace('_', '-'), a))
- return (p, args)
+ args.append((name, a))
+ return (p, opts, args)
class DoCommand (CommandMethod):
def __init__(self, *args, **kwargs):
super(DoCommand, self).__init__(*args, **kwargs)
- self.parser,self.args = command_parser(self.command)
+ self.parser,self.opts,self.args = command_parser(self.command)
def __call__(self, args):
args = self._parse_args(self.command, args)
msg = self.cmd.outqueue.get()
if isinstance(msg, CommandExit):
break
- self.cmd.stdout.write(str(msg))
+ self.cmd.stdout.write(str(msg).rstrip()+'\n')
def _parse_args(self, command, args):
- print 'ARGS:', args, type(args)
- return {}
+ argv = shlex.split(args, comments=True, posix=True)
+ options,args = self.parser.parse_args(argv)
+ params = {}
+ for namearg in self.opts:
+ name,argument = namearg
+ params[name] = getattr(options, name)
+ for namearg,value in zip(self.args, args):
+ name,argument = namearg
+ params[name] = value
+ return params
class HelpCommand (CommandMethod):
def __init__(self, *args, **kwargs):
super(HelpCommand, self).__init__(*args, **kwargs)
- self.parser,self.args = command_parser(self.command)
+ self.parser,self.opts,self.args = command_parser(self.command)
def __call__(self):
blocks = [self.command.help(),