From b22444c48deac1d95514886d1b57326326bbfa54 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Jul 27 2016 00:47:48 +0000 Subject: don't write anything to stdout or stderr Removed some superfluous print statements which were presumably added for debugging. Capture the stderr of rpmbuild and createrepo_c, so that we don't see it normally. If the command fails, the exception message will include the output from the command, which makes it easier to figure out what went wrong if they do fail. The end result is that rpmfluff itself, as well as its test suite, can run without producing any spew. --- diff --git a/rpmfluff.py b/rpmfluff.py index cab4dda..4b60210 100644 --- a/rpmfluff.py +++ b/rpmfluff.py @@ -30,9 +30,7 @@ import os.path import shutil import sys import rpm -#import base64 - -from subprocess import check_output, check_call +import subprocess def _which(cmd): """Hacked Python 3.3+ shutil.which() with limited functionality.""" @@ -291,7 +289,6 @@ class RpmBuild(Buildable): self.__create_directories() specFileName = self.gather_spec_file(self.get_base_dir()) - print(specFileName) sourcesDir = self.get_sources_dir() self.gather_sources(sourcesDir) @@ -307,7 +304,11 @@ class RpmBuild(Buildable): command = ["rpmbuild", "--define", "_topdir %s" % absBaseDir, "--define", "_rpmfilename %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm", "-ba", "--target", arch, specFileName] - log = check_output(command).splitlines(True) + try: + log = subprocess.check_output(command, stderr=subprocess.STDOUT).splitlines(True) + except subprocess.CalledProcessError as e: + raise RuntimeError('rpmbuild command failed with exit status %s: %s\n%s' + % (e.returncode, e.cmd, e.output)) self.__write_log(log, arch) self.check_results() @@ -415,7 +416,7 @@ class GeneratedTarball: self.contents = contents def write_file(self, sourcesDir): - check_call(["rm", "-rf", self.internalPath]) + shutil.rmtree(self.internalPath, ignore_errors=True) os.mkdir(self.internalPath) for content in self.contents: content.write_file(self.internalPath) @@ -423,9 +424,8 @@ class GeneratedTarball: compressionOption = '--gzip' cmd = ["tar", "--create", compressionOption, "--file", os.path.join(sourcesDir, self.sourceName), self.internalPath] - print(cmd) - check_call(cmd) - check_call(["rm", "-rf", self.internalPath]) + subprocess.check_call(cmd) + shutil.rmtree(self.internalPath) hello_world = """#include @@ -467,7 +467,7 @@ defaultChangelogFormat = """* Sun Jan 1 2006 John Doe - %s-% def get_expected_arch(): # FIXME: do this by directly querying rpm python bindings: - evalArch = check_output(['rpm', '--eval', '%{_arch}']) + evalArch = subprocess.check_output(['rpm', '--eval', '%{_arch}']) # first line of output, losing trailing carriage return # convert to a unicode type for python3 @@ -843,7 +843,6 @@ class SimpleRpmBuild(RpmBuild): def check_results(self): for check in self.checks: - print("%s:"%check) check.check(self) def get_built_srpm(self): @@ -1214,7 +1213,11 @@ class YumRepoBuild: for subpackage in pkg.get_subpackage_names(): shutil.copy(pkg.get_built_rpm(arch, name=subpackage), self.repoDir) - check_call(["createrepo_c", self.repoDir]) + try: + subprocess.check_output(["createrepo_c", self.repoDir], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + raise RuntimeError('createrepo_c command failed with exit status %s: %s\n%s' + % (e.returncode, e.cmd, e.output)) testTrigger='print "This is the trigger!' @@ -1804,12 +1807,9 @@ class YumRepoBuildTests(unittest.TestCase): try: repo.make(expectedArch) - print("Yum repo is located at %s"%repo.repoDir) - # Check that the expected files were created: for name in names: rpmFile = os.path.join(repo.repoDir, "test-package-%s-0.1-1.%s.rpm"%(name, expectedArch)) - print(rpmFile) self.assert_is_file(rpmFile) repodataDir = os.path.join(repo.repoDir, "repodata") self.assert_is_dir(repodataDir)