mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 12:12:47 +00:00
Print output live for longer running rpmbuild commands.
This commit is contained in:
parent
9091afd684
commit
527e60bab4
4 changed files with 35 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,8 @@
|
||||||
*.pyo
|
*.pyo
|
||||||
*$py.class
|
*$py.class
|
||||||
*.swp
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.noseids
|
||||||
*.patch
|
*.patch
|
||||||
*#
|
*#
|
||||||
*~
|
*~
|
||||||
|
|
|
@ -194,11 +194,11 @@ class BuilderBase(object):
|
||||||
|
|
||||||
rpmbuild_options = self.rpmbuild_options + self._scl_to_rpmbuild_option()
|
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' % (
|
' "_binary_filedigest_algorithm md5" %s %s %s --nodeps -bs %s' % (
|
||||||
rpmbuild_options, self._get_rpmbuild_dir_options(),
|
rpmbuild_options, self._get_rpmbuild_dir_options(),
|
||||||
define_dist, self.spec_file))
|
define_dist, self.spec_file))
|
||||||
output = run_command(cmd)
|
output = run_command_print(cmd)
|
||||||
print(output)
|
print(output)
|
||||||
self.srpm_location = find_wrote_in_rpmbuild_output(output)[0]
|
self.srpm_location = find_wrote_in_rpmbuild_output(output)[0]
|
||||||
self.artifacts.append(self.srpm_location)
|
self.artifacts.append(self.srpm_location)
|
||||||
|
@ -215,13 +215,13 @@ class BuilderBase(object):
|
||||||
|
|
||||||
rpmbuild_options = self.rpmbuild_options + self._scl_to_rpmbuild_option()
|
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 '
|
'--define "_binary_filedigest_algorithm md5" %s %s %s --clean '
|
||||||
'-ba %s' % (rpmbuild_options,
|
'-ba %s' % (rpmbuild_options,
|
||||||
self._get_rpmbuild_dir_options(), define_dist, self.spec_file))
|
self._get_rpmbuild_dir_options(), define_dist, self.spec_file))
|
||||||
debug(cmd)
|
debug(cmd)
|
||||||
try:
|
try:
|
||||||
output = run_command(cmd)
|
output = run_command_print(cmd)
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
print("")
|
print("")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -235,7 +235,6 @@ class BuilderBase(object):
|
||||||
except Exception:
|
except Exception:
|
||||||
err = sys.exc_info()[1]
|
err = sys.exc_info()[1]
|
||||||
error_out('%s' % str(err))
|
error_out('%s' % str(err))
|
||||||
print(output)
|
|
||||||
files_written = find_wrote_in_rpmbuild_output(output)
|
files_written = find_wrote_in_rpmbuild_output(output)
|
||||||
if len(files_written) < 2:
|
if len(files_written) < 2:
|
||||||
error_out("Error parsing rpmbuild output")
|
error_out("Error parsing rpmbuild output")
|
||||||
|
|
|
@ -18,8 +18,11 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
from tito.compat import *
|
from tito.compat import *
|
||||||
|
from tito.exception import RunCommandException
|
||||||
|
|
||||||
DEFAULT_BUILD_DIR = "/tmp/tito"
|
DEFAULT_BUILD_DIR = "/tmp/tito"
|
||||||
DEFAULT_BUILDER = "builder"
|
DEFAULT_BUILDER = "builder"
|
||||||
|
@ -222,10 +225,27 @@ def run_command(command, print_on_success=False):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def runProcess(cmd):
|
def run_command_print(command):
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
"""
|
||||||
|
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):
|
while(True):
|
||||||
retcode = p.poll() #returns None while subprocess is running
|
retcode = p.poll()
|
||||||
line = p.stdout.readline()
|
line = p.stdout.readline()
|
||||||
yield line
|
yield line
|
||||||
if(retcode is not None):
|
if(retcode is not None):
|
||||||
|
@ -243,7 +263,7 @@ def tag_exists_locally(tag):
|
||||||
def tag_exists_remotely(tag):
|
def tag_exists_remotely(tag):
|
||||||
""" Returns True if the tag exists in the remote git repo. """
|
""" Returns True if the tag exists in the remote git repo. """
|
||||||
try:
|
try:
|
||||||
get_git_repo_url()
|
get_git_repo_url()
|
||||||
except:
|
except:
|
||||||
sys.stderr.write('Warning: remote.origin do not exist. Assuming --offline, for remote tag checking.\n')
|
sys.stderr.write('Warning: remote.origin do not exist. Assuming --offline, for remote tag checking.\n')
|
||||||
return False
|
return False
|
||||||
|
@ -505,7 +525,7 @@ def create_tgz(git_root, prefix, commit, relative_dir, rel_eng_dir,
|
||||||
#if not os.path.exists(timestamp_script):
|
#if not os.path.exists(timestamp_script):
|
||||||
# error_out("Unable to locate required script: %s" % 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
|
relative_git_dir = "%s" % relative_dir
|
||||||
if relative_git_dir in ['/', './']:
|
if relative_git_dir in ['/', './']:
|
||||||
relative_git_dir = ""
|
relative_git_dir = ""
|
||||||
|
@ -637,7 +657,8 @@ def find_wrote_in_rpmbuild_output(output):
|
||||||
"""
|
"""
|
||||||
paths = []
|
paths = []
|
||||||
look_for = "Wrote: "
|
look_for = "Wrote: "
|
||||||
for line in output.split("\n"):
|
for line in output.split('\n'):
|
||||||
|
print("Checking: %s" % line)
|
||||||
if line.startswith(look_for):
|
if line.startswith(look_for):
|
||||||
paths.append(line[len(look_for):])
|
paths.append(line[len(look_for):])
|
||||||
debug("Found wrote line: %s" % paths[-1])
|
debug("Found wrote line: %s" % paths[-1])
|
||||||
|
|
|
@ -32,8 +32,8 @@ class TitoException(Exception):
|
||||||
|
|
||||||
class RunCommandException(Exception):
|
class RunCommandException(Exception):
|
||||||
""" Raised by run_command() """
|
""" Raised by run_command() """
|
||||||
def __init__(self, msg, command, status, output):
|
def __init__(self, command, status, output):
|
||||||
Exception.__init__(self, msg)
|
Exception.__init__(self, "Error running command: %s" % command)
|
||||||
self.command = command
|
self.command = command
|
||||||
self.status = status
|
self.status = status
|
||||||
self.output = output
|
self.output = output
|
||||||
|
|
Loading…
Add table
Reference in a new issue