[Git][reproducible-builds/diffoscope][master] Log all calls to subprocess.check_output by using a wrapper. (Closes:...

Chris Lamb gitlab at salsa.debian.org
Mon Jun 8 15:02:42 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
fe446ea2 by Chris Lamb at 2020-06-08T15:36:40+01:00
Log all calls to subprocess.check_output by using a wrapper. (Closes: reproducible-builds/diffoscope#151)

- - - - -


11 changed files:

- diffoscope/comparators/cbfs.py
- diffoscope/comparators/directory.py
- diffoscope/comparators/elf.py
- diffoscope/comparators/gif.py
- diffoscope/comparators/haskell.py
- diffoscope/comparators/image.py
- diffoscope/comparators/iso9660.py
- diffoscope/comparators/macho.py
- diffoscope/comparators/ppu.py
- diffoscope/comparators/squashfs.py
- diffoscope/comparators/utils/command.py


Changes:

=====================================
diffoscope/comparators/cbfs.py
=====================================
@@ -30,7 +30,7 @@ from diffoscope.difference import Difference
 
 from .utils.file import File
 from .utils.archive import Archive
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 logger = logging.getLogger(__name__)
 
@@ -54,7 +54,7 @@ class CbfsContainer(Archive):
     @tool_required("cbfstool")
     def entries(self, path):
         cmd = ["cbfstool", path, "print"]
-        output = subprocess.check_output(cmd).decode("utf-8")
+        output = our_check_output(cmd)
         header = True
         for line in output.rstrip("\n").split("\n"):
             if header:
@@ -88,7 +88,7 @@ class CbfsContainer(Archive):
             dest_path,
         ]
         logger.debug("cbfstool extract %s to %s", member_name, dest_path)
-        subprocess.check_call(
+        our_check_output(
             cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
         )
         return dest_path


=====================================
diffoscope/comparators/directory.py
=====================================
@@ -32,7 +32,7 @@ from diffoscope.progress import Progress
 from diffoscope.difference import Difference
 
 from .binary import FilesystemFile
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 from .utils.container import Container
 
 logger = logging.getLogger(__name__)
@@ -100,7 +100,7 @@ def lsattr(path):
     """
 
     try:
-        output = subprocess.check_output(
+        output = our_check_output(
             ["lsattr", "-d", path], stderr=subprocess.STDOUT
         ).decode("utf-8")
         return output.split()[0]


=====================================
diffoscope/comparators/elf.py
=====================================
@@ -32,7 +32,7 @@ from diffoscope.difference import Difference
 
 from .deb import DebFile, get_build_id_map
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 from .utils.container import Container
 
 DEBUG_SECTION_GROUPS = (
@@ -168,7 +168,7 @@ class ReadElfSection(Readelf):
     @staticmethod
     def base_options():
         if not hasattr(ReadElfSection, "_base_options"):
-            output = subprocess.check_output(
+            output = our_check_output(
                 [get_tool_name("readelf"), "--help"],
                 stderr=subprocess.DEVNULL,
             ).decode("us-ascii", errors="replace")
@@ -381,7 +381,7 @@ class ElfStringSection(ElfSection):
 @tool_required("readelf")
 def get_build_id(path):
     try:
-        output = subprocess.check_output(
+        output = our_check_output(
             [get_tool_name("readelf"), "--notes", path],
             stderr=subprocess.DEVNULL,
         )
@@ -403,7 +403,7 @@ def get_build_id(path):
 @tool_required("readelf")
 def get_debug_link(path):
     try:
-        output = subprocess.check_output(
+        output = our_check_output(
             [get_tool_name("readelf"), "--string-dump=.gnu_debuglink", path],
             stderr=subprocess.DEVNULL,
         )
@@ -442,9 +442,7 @@ class ElfContainer(Container):
             "--section-headers",
             self.source.path,
         ]
-        output = subprocess.check_output(
-            cmd, shell=False, stderr=subprocess.DEVNULL
-        )
+        output = our_check_output(cmd, shell=False, stderr=subprocess.DEVNULL)
         has_debug_symbols = False
 
         try:
@@ -573,7 +571,7 @@ class ElfContainer(Container):
         os.makedirs(os.path.dirname(dest_path), exist_ok=True)
 
         def objcopy(*args):
-            subprocess.check_call(
+            our_check_output(
                 (get_tool_name("objcopy"),) + args,
                 shell=False,
                 stderr=subprocess.DEVNULL,


=====================================
diffoscope/comparators/gif.py
=====================================
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2017-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2017-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ from diffoscope.difference import Difference
 
 from .image import pixel_difference, flicker_difference, same_size
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 logger = logging.getLogger(__name__)
 
@@ -52,8 +52,7 @@ class Gifbuild(Command):
 def is_image_static(image):
     try:
         return (
-            subprocess.check_output(("identify", "-format", "%n", image.path))
-            == b"1"
+            our_check_output(("identify", "-format", "%n", image.path)) == b"1"
         )
     except subprocess.CalledProcessError:
         return False


=====================================
diffoscope/comparators/haskell.py
=====================================
@@ -3,7 +3,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
-# Copyright © 2015-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2015-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 HI_MAGIC_32 = struct.pack(">I", 0x1FACE)
 HI_MAGIC_64 = struct.pack(">I", 0x1FACE64)
@@ -82,9 +82,7 @@ class HiFile(File):
         if not hasattr(HiFile, "hi_version"):
             try:
                 with profile("command", "ghc"):
-                    output = subprocess.check_output(
-                        ["ghc", "--numeric-version"]
-                    )
+                    output = our_check_output(["ghc", "--numeric-version"])
             except (OSError, subprocess.CalledProcessError):
                 HiFile.hi_version = None
                 logger.debug("Unable to read GHC version")


=====================================
diffoscope/comparators/image.py
=====================================
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2015-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2015-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@ from diffoscope.tempfiles import get_named_temporary_file
 from diffoscope.difference import Difference, VisualDifference
 
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 re_ansi_escapes = re.compile(r"\x1b[^m]*m")
 
@@ -79,7 +79,7 @@ def pixel_difference(image1_path, image2_path):
     compared_filename = get_named_temporary_file(suffix=".png").name
 
     try:
-        subprocess.check_call(
+        our_check_output(
             (
                 "compare",
                 image1_path,
@@ -104,7 +104,7 @@ def pixel_difference(image1_path, image2_path):
 def flicker_difference(image1_path, image2_path):
     compared_filename = get_named_temporary_file(suffix=".gif").name
 
-    subprocess.check_call(
+    our_check_output(
         (
             "convert",
             "-delay",
@@ -127,9 +127,7 @@ def flicker_difference(image1_path, image2_path):
 
 @tool_required("identify")
 def get_image_size(image_path):
-    return subprocess.check_output(
-        ("identify", "-format", "%[h]x%[w]", image_path)
-    )
+    return our_check_output(("identify", "-format", "%[h]x%[w]", image_path))
 
 
 def same_size(image1, image2):
@@ -222,6 +220,6 @@ class ICOImageFile(File):
     def convert(file):
         result = get_named_temporary_file(suffix=".png").name
 
-        subprocess.check_call(("convert", file.path, result))
+        our_check_output(("convert", file.path, result))
 
         return result


=====================================
diffoscope/comparators/iso9660.py
=====================================
@@ -25,14 +25,14 @@ from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 from .utils.libarchive import LibarchiveContainerWithFilelist
 
 
 @tool_required("isoinfo")
 def get_iso9660_names(path):
     return (
-        subprocess.check_output(
+        our_check_output(
             (
                 "isoinfo",
                 "-R",  # Always use RockRidge for names


=====================================
diffoscope/comparators/macho.py
=====================================
@@ -4,7 +4,7 @@
 #
 # Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
 # Copyright © 2015 Clemens Lang <cal at macports.org>
-# Copyright © 2016-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,13 +20,12 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import re
-import subprocess
 
 from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 
 class Otool(Command):
@@ -80,9 +79,7 @@ class MachoFile(File):
     @staticmethod
     @tool_required("lipo")
     def get_arch_from_macho(path):
-        lipo_output = subprocess.check_output(["lipo", "-info", path]).decode(
-            "utf-8"
-        )
+        lipo_output = our_check_output(["lipo", "-info", path]).decode("utf-8")
         lipo_match = MachoFile.RE_EXTRACT_ARCHS.match(lipo_output)
         if lipo_match is None:
             raise ValueError(


=====================================
diffoscope/comparators/ppu.py
=====================================
@@ -5,7 +5,7 @@
 # Copyright © 2015 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
 # Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
 # Copyright © 2015 Paul Gevers <elbrus at debian.org>
-# Copyright © 2016-2019 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2020 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@ from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
 from .utils.file import File
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 logger = logging.getLogger(__name__)
 
@@ -78,7 +78,7 @@ class PpuFile(File):
         if not hasattr(PpuFile, "ppu_version"):
             try:
                 with profile("command", "ppudump"):
-                    subprocess.check_output(
+                    our_check_output(
                         ["ppudump", "-vh", file.path],
                         stderr=subprocess.STDOUT,
                     )


=====================================
diffoscope/comparators/squashfs.py
=====================================
@@ -36,7 +36,7 @@ from .device import Device
 from .symlink import Symlink
 from .directory import Directory
 from .utils.archive import Archive, ArchiveMember
-from .utils.command import Command
+from .utils.command import Command, our_check_output
 
 logger = logging.getLogger(__name__)
 
@@ -260,7 +260,7 @@ class SquashfsContainer(Archive):
 
         logger.debug("Extracting %s to %s", self.source.path, self._temp_dir)
 
-        output = subprocess.check_output(
+        output = our_check_output(
             (
                 "unsquashfs",
                 "-n",


=====================================
diffoscope/comparators/utils/command.py
=====================================
@@ -118,3 +118,9 @@ class Command(metaclass=abc.ABCMeta):
     @property
     def stdout(self):
         return self._process.stdout.splitlines(True)
+
+
+def our_check_output(cmd, *args, **kwargs):
+    logger.debug("Calling external command %r", cmd)
+
+    return subprocess.check_output(cmd, *args, **kwargs)



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/fe446ea2eda5f9649b829985f9fd01b151b81fe5

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/fe446ea2eda5f9649b829985f9fd01b151b81fe5
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200608/92a0f8f4/attachment.htm>


More information about the rb-commits mailing list