58
58
for cmdname, cmdclass in get_all_cmds():
59
59
if cmd in cmdclass.aliases:
60
60
return cmdname, cmdclass
62
raise BzrCommandError("unknown command %r" % cmd)
62
cmdclass = ExternalCommand.find_command(cmd)
66
raise BzrCommandError("unknown command %r" % cmd)
118
class ExternalCommand(Command):
119
"""Class to wrap external commands.
121
We cheat a little here, when get_cmd_class() calls us we actually give it back
122
an object we construct that has the appropriate path, help, options etc for the
125
When run_bzr() tries to instantiate that 'class' it gets caught by the __call__
126
method, which we override to call the Command.__init__ method. That then calls
127
our run method which is pretty straight forward.
129
The only wrinkle is that we have to map bzr's dictionary of options and arguments
130
back into command line options and arguments for the script.
133
def find_command(cls, cmd):
134
bzrpath = os.environ.get('BZRPATH', '')
136
for dir in bzrpath.split(':'):
137
path = os.path.join(dir, cmd)
138
if os.path.isfile(path):
139
return ExternalCommand(path)
143
find_command = classmethod(find_command)
145
def __init__(self, path):
148
pipe = os.popen('%s --bzr-usage' % path, 'r')
149
self.takes_options = pipe.readline().split()
150
self.takes_args = pipe.readline().split()
153
pipe = os.popen('%s --bzr-help' % path, 'r')
154
self.__doc__ = pipe.read()
157
def __call__(self, options, arguments):
158
Command.__init__(self, options, arguments)
161
def run(self, **kargs):
169
if OPTIONS.has_key(name):
171
opts.append('--%s' % name)
172
if value is not None and value is not True:
173
opts.append(str(value))
175
# it's an arg, or arg list
176
if type(value) is not list:
182
self.status = os.spawnv(os.P_WAIT, self.path, [self.path] + opts + args)
115
186
class cmd_status(Command):
116
187
"""Display status summary.