From 2f529b4f99eba3d1525c641a5c899a0a95614f20 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 20 Dec 2012 14:44:56 +0100 Subject: [PATCH] add custom commands + usage + ability to follow an stdout command --- buildozer/__init__.py | 36 ++++++++++++++++++++++++++++++------ buildozer/target.py | 10 ++++++++++ buildozer/targets/android.py | 7 ++++++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/buildozer/__init__.py b/buildozer/__init__.py index 22d9419..0506bd2 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -28,6 +28,8 @@ from shutil import copyfile, rmtree class Buildozer(object): + standard_cmds = ('clean', 'update', 'debug', 'release', 'deploy', 'run') + def __init__(self, filename='buildozer.spec', target=None): super(Buildozer, self).__init__() self.environ = {} @@ -85,16 +87,25 @@ class Buildozer(object): env.update(self.environ) kwargs.setdefault('env', env) self.log('run %r' % command) - c = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, **kwargs) - ret = c.communicate() - if c.returncode != 0: + process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, **kwargs) + ret_stdout = '' + 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 '-- stdout output' - print ret[0] + print ret_stdout print '-- stderr output' print ret[1] print '--- end commend failed' - return ret + return (ret_stdout, ret[1]) def do_config_requirements(self): pass @@ -302,7 +313,8 @@ class Buildozer(object): print 'Usage: buildozer [target] [command1] [command2]' print 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() print ' {0:<18} {1}'.format(target, doc) @@ -325,6 +337,18 @@ class Buildozer(object): print ' release Build the application in release mode' print ' deploy Deploy 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 diff --git a/buildozer/target.py b/buildozer/target.py index 0296c85..08e0a1f 100644 --- a/buildozer/target.py +++ b/buildozer/target.py @@ -14,6 +14,16 @@ class Target(object): def compile_platform(self): 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): if not args: print 'ERROR: missing target command' diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index ae95327..37cec98 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -389,7 +389,12 @@ class TargetAndroid(Target): 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)