#12 stop the spam
Merged 7 years ago by jhutar. Opened 7 years ago by dcallagh.
dcallagh/rpmfluff stop-the-spam  into  master

file modified
+15 -15
@@ -30,9 +30,7 @@ 

  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 @@ 

          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 @@ 

              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 @@ 

          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 @@ 

          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 <stdio.h>
@@ -467,7 +467,7 @@ 

  

  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 @@ 

  

      def check_results(self):

          for check in self.checks:

-             print("%s:"%check)

              check.check(self)

  

      def get_built_srpm(self):
@@ -1214,7 +1213,11 @@ 

                  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 @@ 

          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)

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.

Pull-Request has been merged by jhutar

7 years ago

Never thought about this, thank you!

Ahh really? It's been driving me crazy since we first started using rpmfluff :-)

Metadata