From a5704e565550c9503767c5abf2600de36acc511d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 4 Sep 2013 16:45:19 +0200 Subject: [PATCH] Finish -v/--verbose output+error handling --- fdroidserver/build.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index 10925126..f3beca48 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -422,7 +422,9 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d print output raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version'])) + p = None output = "" + error = "" # Build the release... if 'maven' in thisbuild: print "Building Maven project..." @@ -440,13 +442,19 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d if 'mvnflags' in thisbuild: mvncmd += thisbuild['mvnflags'] - p = subprocess.Popen(mvncmd, cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - for line in p.stdout.readlines(): + p = subprocess.Popen(mvncmd, cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + for line in iter(p.stdout.readline, ''): if verbose: # Output directly to console sys.stdout.write(line) sys.stdout.flush() output += line + for line in iter(p.stderr.readline, ''): + if verbose: + # Output directly to console + sys.stdout.write(line) + sys.stdout.flush() + error += line elif 'gradle' in thisbuild: print "Building Gradle project..." @@ -491,12 +499,18 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d print "Running %s on %s" % (" ".join(commands), gradle_dir) p = subprocess.Popen(commands, cwd=gradle_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for line in p.stdout.readlines(): + for line in iter(p.stdout.readline, ''): if verbose: # Output directly to console sys.stdout.write(line) sys.stdout.flush() output += line + for line in iter(p.stderr.readline, ''): + if verbose: + # Output directly to console + sys.stdout.write(line) + sys.stdout.flush() + error += line else: print "Building Ant project..." @@ -508,13 +522,19 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d else: antcommands += ['release'] p = subprocess.Popen(antcommands, cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for line in p.stdout.readlines(): + for line in iter(p.stdout.readline, ''): if verbose: # Output directly to console sys.stdout.write(line) sys.stdout.flush() output += line - _, error = p.communicate() + for line in iter(p.stderr.readline, ''): + if verbose: + # Output directly to console + sys.stdout.write(line) + sys.stdout.flush() + error += line + p.communicate() if p.returncode != 0: raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), output.strip(), error.strip()) if install: