19
19
# ExternalCommands to handle it differently to internal commands?
24
22
from bzrlib.commands import Command
27
25
class ExternalCommand(Command):
28
"""Class to wrap external commands."""
26
"""Class to wrap external commands.
28
The only wrinkle is that we have to map bzr's dictionary of
29
options and arguments back into command line options and arguments
31
34
def find_command(cls, cmd):
43
46
def __init__(self, path):
49
pipe = os.popen('%s --bzr-usage' % path, 'r')
50
self.takes_options = pipe.readline().split()
52
for opt in self.takes_options:
53
if not opt in OPTIONS:
54
raise BzrError("Unknown option '%s' returned by external command %s"
57
# TODO: Is there any way to check takes_args is valid here?
58
self.takes_args = pipe.readline().split()
60
if pipe.close() is not None:
61
raise BzrError("Failed funning '%s --bzr-usage'" % path)
63
pipe = os.popen('%s --bzr-help' % path, 'r')
64
self.__doc__ = pipe.read()
65
if pipe.close() is not None:
66
raise BzrError("Failed funning '%s --bzr-help'" % path)
68
def __call__(self, options, arguments):
69
Command.__init__(self, options, arguments)
48
return self.path.split(os.sep)[-1]
51
def run(self, *args, **kwargs):
52
raise NotImplementedError('should not be called on %r' % self)
55
def run_argv(self, argv):
56
return os.spawnv(os.P_WAIT, self.path, [self.path] + argv)
60
m = 'external command from %s\n\n' % self.path
61
pipe = os.popen('%s --help' % self.path)
62
return m + pipe.read()
73
raise NotImplementedError()
75
def run(self, **kargs):
76
raise NotImplementedError()
84
optname = name.replace('_','-')
86
if OPTIONS.has_key(optname):
88
opts.append('--%s' % optname)
89
if value is not None and value is not True:
90
opts.append(str(value))
92
# it's an arg, or arg list
93
if type(value) is not list:
99
self.status = os.spawnv(os.P_WAIT, self.path, [self.path] + opts + args)