diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index f0db37a..2d4751a 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -225,7 +225,8 @@ class BuilderBase(object): ' "_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_print(cmd) + run_command_func = run_command if self.quiet else run_command_print + output = run_command_func(cmd) self.srpm_location = find_wrote_in_rpmbuild_output(output)[0] self.artifacts.append(self.srpm_location) @@ -1142,25 +1143,26 @@ class MockBuilder(Builder): self.normal_builder.cleanup() def _build_in_mock(self): + run_command_func = run_command if self.quiet else run_command_print if not self.speedup: print("Initializing mock...") - run_command("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag)) + run_command_func("mock %s -r %s --init" % (self.mock_cmd_args, self.mock_tag)) else: print("Skipping mock --init due to speedup option.") print("Installing deps in mock...") - run_command("mock %s -r %s %s" % ( + run_command_func("mock %s -r %s %s" % ( self.mock_cmd_args, self.mock_tag, self.srpm_location)) print("Building RPMs in mock...") - run_command('mock %s -r %s --rebuild %s' % + run_command_func('mock %s -r %s --rebuild %s' % (self.mock_cmd_args, self.mock_tag, self.srpm_location)) mock_output_dir = os.path.join(self.rpmbuild_dir, "mockoutput") - run_command("mock %s -r %s --copyout /builddir/build/RPMS/ %s" % + run_command_func("mock %s -r %s --copyout /builddir/build/RPMS/ %s" % (self.mock_cmd_args, self.mock_tag, mock_output_dir)) # Copy everything mock wrote out to /tmp/tito: files = os.listdir(mock_output_dir) - run_command("cp -v %s/*.rpm %s" % + run_command_func("cp -v %s/*.rpm %s" % (mock_output_dir, self.rpmbuild_basedir)) print info_out("Wrote:") diff --git a/src/tito/common.py b/src/tito/common.py index cc189dd..cc8b551 100644 --- a/src/tito/common.py +++ b/src/tito/common.py @@ -443,16 +443,29 @@ def run_command_print(command): output = [] env = os.environ.copy() env['LC_ALL'] = 'C' - p = subprocess.Popen(shlex.split(command), - stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, - universal_newlines=True) - for line in run_subprocess(p): - line = line.rstrip('\n') - print(line) - output.append(line) - print("\n"), - if p.poll() > 0: - raise RunCommandException(command, p.poll(), "\n".join(output)) + p = None + try: + p = subprocess.Popen(shlex.split(command), + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, + universal_newlines=True) + except OSError as e: + status = e.errno + output = e.strerror + if p: + for line in run_subprocess(p): + line = line.rstrip('\n') + print(line) + output.append(line) + print("\n"), + status = p.poll() + if status > 0: + msgs = [ + "Error running command: %s\n" % command, + "Status code: %s\n" % status, + "Command output: %s\n" % output, + ] + error_out(msgs, die=False) + raise RunCommandException(command, status, "\n".join(output)) return '\n'.join(output) @@ -462,7 +475,7 @@ def run_subprocess(p): line = p.stdout.readline() if len(line) > 0: yield line - if(retcode is not None): + if retcode is not None: break