add custom commands + usage + ability to follow an stdout command

This commit is contained in:
Mathieu Virbel 2012-12-20 14:44:56 +01:00
parent b348237188
commit 2f529b4f99
3 changed files with 46 additions and 7 deletions

View file

@ -28,6 +28,8 @@ from shutil import copyfile, rmtree
class Buildozer(object): class Buildozer(object):
standard_cmds = ('clean', 'update', 'debug', 'release', 'deploy', 'run')
def __init__(self, filename='buildozer.spec', target=None): def __init__(self, filename='buildozer.spec', target=None):
super(Buildozer, self).__init__() super(Buildozer, self).__init__()
self.environ = {} self.environ = {}
@ -85,16 +87,25 @@ class Buildozer(object):
env.update(self.environ) env.update(self.environ)
kwargs.setdefault('env', env) kwargs.setdefault('env', env)
self.log('run %r' % command) self.log('run %r' % command)
c = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, **kwargs) process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, **kwargs)
ret = c.communicate() ret_stdout = ''
if c.returncode != 0: while True:
nextline = process.stdout.readline()
if nextline == '' and process.poll() != None:
break
ret_stdout += nextline
stdout.write(nextline)
stdout.flush()
ret = process.communicate()
if process.returncode != 0:
print '--- command failed' print '--- command failed'
print '-- stdout output' print '-- stdout output'
print ret[0] print ret_stdout
print '-- stderr output' print '-- stderr output'
print ret[1] print ret[1]
print '--- end commend failed' print '--- end commend failed'
return ret return (ret_stdout, ret[1])
def do_config_requirements(self): def do_config_requirements(self):
pass pass
@ -302,7 +313,8 @@ class Buildozer(object):
print 'Usage: buildozer [target] [command1] [command2]' print 'Usage: buildozer [target] [command1] [command2]'
print print
print 'Available targets:' print 'Available targets:'
for target, m in self.targets(): targets = list(self.targets())
for target, m in targets:
doc = m.__doc__.strip().splitlines()[0].strip() doc = m.__doc__.strip().splitlines()[0].strip()
print ' {0:<18} {1}'.format(target, doc) print ' {0:<18} {1}'.format(target, doc)
@ -325,6 +337,18 @@ class Buildozer(object):
print ' release Build the application in release mode' print ' release Build the application in release mode'
print ' deploy Deploy the application on the device' print ' deploy Deploy the application on the device'
print ' run Run the application on the device' print ' run Run the application on the device'
for target, m in targets:
mt = m.get_target(self)
commands = mt.get_custom_commands()
if not commands:
continue
print
print 'Target "{0}" commands:'.format(target)
for command, doc in commands:
doc = doc.strip().splitlines()[0].strip()
print ' {0:<18} {1}'.format(command, doc)
print print

View file

@ -14,6 +14,16 @@ class Target(object):
def compile_platform(self): def compile_platform(self):
pass pass
def get_custom_commands(self):
result = []
for x in dir(self):
if not x.startswith('cmd_'):
continue
if x[4:] in self.buildozer.standard_cmds:
continue
result.append((x[4:], getattr(self, x).__doc__))
return result
def run_commands(self, args): def run_commands(self, args):
if not args: if not args:
print 'ERROR: missing target command' print 'ERROR: missing target command'

View file

@ -389,7 +389,12 @@ class TargetAndroid(Target):
self.buildozer.log('Application started on the device.') self.buildozer.log('Application started on the device.')
def cmd_logcat(self, *args):
'''Show the log from the device
'''
self.check_requirements()
self.buildozer.cmd('{adb} logcat'.format(adb=self.adb_cmd),
cwd=self.buildozer.global_platform_dir)