Print output live for longer running rpmbuild commands.

This commit is contained in:
Devan Goodwin 2014-03-11 09:12:49 -03:00
parent 9091afd684
commit 527e60bab4
4 changed files with 35 additions and 13 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@
*.pyo
*$py.class
*.swp
*.swo
.noseids
*.patch
*#
*~

View file

@ -194,11 +194,11 @@ class BuilderBase(object):
rpmbuild_options = self.rpmbuild_options + self._scl_to_rpmbuild_option()
cmd = ('LC_ALL=C rpmbuild --define "_source_filedigest_algorithm md5" --define'
cmd = ('rpmbuild --define "_source_filedigest_algorithm md5" --define'
' "_binary_filedigest_algorithm md5" %s %s %s --nodeps -bs %s' % (
rpmbuild_options, self._get_rpmbuild_dir_options(),
define_dist, self.spec_file))
output = run_command(cmd)
output = run_command_print(cmd)
print(output)
self.srpm_location = find_wrote_in_rpmbuild_output(output)[0]
self.artifacts.append(self.srpm_location)
@ -215,13 +215,13 @@ class BuilderBase(object):
rpmbuild_options = self.rpmbuild_options + self._scl_to_rpmbuild_option()
cmd = ('LC_ALL=C rpmbuild --define "_source_filedigest_algorithm md5" '
cmd = ('rpmbuild --define "_source_filedigest_algorithm md5" '
'--define "_binary_filedigest_algorithm md5" %s %s %s --clean '
'-ba %s' % (rpmbuild_options,
self._get_rpmbuild_dir_options(), define_dist, self.spec_file))
debug(cmd)
try:
output = run_command(cmd)
output = run_command_print(cmd)
except (KeyboardInterrupt, SystemExit):
print("")
exit(1)
@ -235,7 +235,6 @@ class BuilderBase(object):
except Exception:
err = sys.exc_info()[1]
error_out('%s' % str(err))
print(output)
files_written = find_wrote_in_rpmbuild_output(output)
if len(files_written) < 2:
error_out("Error parsing rpmbuild output")

View file

@ -18,8 +18,11 @@ import os
import re
import sys
import traceback
import subprocess
import shlex
from tito.compat import *
from tito.exception import RunCommandException
DEFAULT_BUILD_DIR = "/tmp/tito"
DEFAULT_BUILDER = "builder"
@ -222,10 +225,27 @@ def run_command(command, print_on_success=False):
return output
def runProcess(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def run_command_print(command):
"""
Simliar to run_command but prints each line of output on the fly.
"""
output = []
env = os.environ.copy()
env['LC_ALL'] = 'C'
p = subprocess.Popen(shlex.split(command),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
for line in run_subprocess(p):
print(line),
output.append(line.rstrip('\n'))
print("\n"),
if p.poll() > 0:
raise RunCommandException(command, p.poll(), "\n".join(output))
return '\n'.join(output)
def run_subprocess(p):
while(True):
retcode = p.poll() #returns None while subprocess is running
retcode = p.poll()
line = p.stdout.readline()
yield line
if(retcode is not None):
@ -505,7 +525,7 @@ def create_tgz(git_root, prefix, commit, relative_dir, rel_eng_dir,
#if not os.path.exists(timestamp_script):
# error_out("Unable to locate required script: %s" % timestamp_script)
# Accomodate standalone projects with specfile in root of git repo:
# Accomodate standalone projects with specfile i root of git repo:
relative_git_dir = "%s" % relative_dir
if relative_git_dir in ['/', './']:
relative_git_dir = ""
@ -637,7 +657,8 @@ def find_wrote_in_rpmbuild_output(output):
"""
paths = []
look_for = "Wrote: "
for line in output.split("\n"):
for line in output.split('\n'):
print("Checking: %s" % line)
if line.startswith(look_for):
paths.append(line[len(look_for):])
debug("Found wrote line: %s" % paths[-1])

View file

@ -32,8 +32,8 @@ class TitoException(Exception):
class RunCommandException(Exception):
""" Raised by run_command() """
def __init__(self, msg, command, status, output):
Exception.__init__(self, msg)
def __init__(self, command, status, output):
Exception.__init__(self, "Error running command: %s" % command)
self.command = command
self.status = status
self.output = output