[Git][reproducible-builds/diffoscope][master] 2 commits: Emit a logging message when ppudump version does not match file header.

Chris Lamb gitlab at salsa.debian.org
Mon Aug 10 10:25:45 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
8ce4515f by Chris Lamb at 2020-08-10T11:18:19+01:00
Emit a logging message when ppudump version does not match file header.

- - - - -
26d9a39f by Frazer Clews at 2020-08-10T11:25:29+01:00
Apply some pylint suggestions for better codebase.

- bad-except-order
- bad-classmethod-argument
- super-init-not-called
- dangerous-default-value

Signed-off-by: Chris Lamb <lamby at debian.org>

- - - - -


7 changed files:

- diffoscope/comparators/debian.py
- diffoscope/comparators/missing_file.py
- diffoscope/comparators/ppu.py
- diffoscope/comparators/utils/file.py
- diffoscope/exc.py
- diffoscope/main.py
- diffoscope/presenters/utils.py


Changes:

=====================================
diffoscope/comparators/debian.py
=====================================
@@ -35,7 +35,7 @@ logger = logging.getLogger(__name__)
 
 class DebControlMember(File):
     def __init__(self, container, member_name):
-        self._container = container
+        super().__init__(container)
         self._name = member_name
         self._path = None
 


=====================================
diffoscope/comparators/missing_file.py
=====================================
@@ -46,6 +46,7 @@ class MissingFile(File, AbstractMissingType):
         return False
 
     def __init__(self, path, other_file=None):
+        super().__init__()
         self._name = path
         self._other_file = other_file
 


=====================================
diffoscope/comparators/ppu.py
=====================================
@@ -97,7 +97,17 @@ class PpuFile(File):
             except OSError:
                 PpuFile.ppu_version = None
                 logger.debug("Unable to read PPU version")
-        return PpuFile.ppu_version == ppu_version
+
+        if PpuFile.ppu_version != ppu_version:
+            logger.debug(
+                "ppudump version (%s) does not match header of %s (%s)",
+                PpuFile.ppu_version,
+                file.name,
+                ppu_version,
+            )
+            return False
+
+        return True
 
     def compare_details(self, other, source=None):
         return [Difference.from_command(Ppudump, self.path, other.path)]


=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -69,34 +69,34 @@ class File(metaclass=abc.ABCMeta):
     if hasattr(magic, "open"):  # use Magic-file-extensions from file
 
         @classmethod
-        def guess_file_type(self, path):
-            if not hasattr(self, "_mimedb"):
-                self._mimedb = magic.open(magic.NONE)
-                self._mimedb.load()
-            return self._mimedb.file(
+        def guess_file_type(cls, path):
+            if not hasattr(cls, "_mimedb"):
+                cls._mimedb = magic.open(magic.NONE)
+                cls._mimedb.load()
+            return cls._mimedb.file(
                 path.encode("utf-8", errors="surrogateescape")
             )
 
         @classmethod
-        def guess_encoding(self, path):
-            if not hasattr(self, "_mimedb_encoding"):
-                self._mimedb_encoding = magic.open(magic.MAGIC_MIME_ENCODING)
-                self._mimedb_encoding.load()
-            return self._mimedb_encoding.file(path)
+        def guess_encoding(cls, path):
+            if not hasattr(cls, "_mimedb_encoding"):
+                cls._mimedb_encoding = magic.open(magic.MAGIC_MIME_ENCODING)
+                cls._mimedb_encoding.load()
+            return cls._mimedb_encoding.file(path)
 
     else:  # use python-magic
 
         @classmethod
-        def guess_file_type(self, path):
-            if not hasattr(self, "_mimedb"):
-                self._mimedb = magic.Magic()
-            return maybe_decode(self._mimedb.from_file(path))
+        def guess_file_type(cls, path):
+            if not hasattr(cls, "_mimedb"):
+                cls._mimedb = magic.Magic()
+            return maybe_decode(cls._mimedb.from_file(path))
 
         @classmethod
-        def guess_encoding(self, path):
-            if not hasattr(self, "_mimedb_encoding"):
-                self._mimedb_encoding = magic.Magic(mime_encoding=True)
-            return maybe_decode(self._mimedb_encoding.from_file(path))
+        def guess_encoding(cls, path):
+            if not hasattr(cls, "_mimedb_encoding"):
+                cls._mimedb_encoding = magic.Magic(mime_encoding=True)
+            return maybe_decode(cls._mimedb_encoding.from_file(path))
 
     def __init__(self, container=None):
         self._comments = []
@@ -353,8 +353,8 @@ class File(metaclass=abc.ABCMeta):
 
         return compare_binary_files(self, other, source)
 
-    @classmethod
-    def _mangle_file_type(self, val):
+    @staticmethod
+    def _mangle_file_type(val):
         # Strip off trailing (eg.) "original size modulo 2^32 671" from
         # gzip compressed data as this is just a symptom of the contents itself
         # changing that will be reflected elsewhere.


=====================================
diffoscope/exc.py
=====================================
@@ -23,12 +23,14 @@ from .tools import get_tool_name, get_package_provider
 
 class OutputParsingError(Exception):
     def __init__(self, command, object):
+        super().__init__()
         self.command = command
         self.object_class = object.__class__
 
 
 class RequiredToolNotFound(Exception):
     def __init__(self, command):
+        super().__init__()
         self.command = get_tool_name(command)
 
     def get_comment(self, infix=""):
@@ -50,5 +52,6 @@ class RequiredToolNotFound(Exception):
 
 class ContainerExtractionError(Exception):
     def __init__(self, pathname, wrapped_exc):
+        super().__init__()
         self.pathname = pathname
         self.wrapped_exc = wrapped_exc


=====================================
diffoscope/main.py
=====================================
@@ -746,6 +746,8 @@ def main(args=None):
             # Call main entry point
             sys.exit(run_diffoscope(parsed_args))
 
+    except BrokenPipeError:
+        sys.exit(2)
     except OSError as e:
         if e.errno != errno.ENOSPC:
             raise
@@ -754,8 +756,6 @@ def main(args=None):
     except KeyboardInterrupt:
         logger.error("Keyboard Interrupt")
         sys.exit(2)
-    except BrokenPipeError:
-        sys.exit(2)
     except Exception:
         sys.stderr.buffer.write(line_eraser())
         traceback.print_exc()


=====================================
diffoscope/presenters/utils.py
=====================================
@@ -338,8 +338,10 @@ class PartialString:
     def size(self, hole_size=1):
         return self.base_len + hole_size * self.num_holes
 
-    def pformat(self, mapping={}):
+    def pformat(self, mapping=None):
         """Partially apply a mapping, returning a new PartialString."""
+        if mapping is None:
+            mapping = {}
         real_mapping, new_holes = self._pformat(mapping, True)
         return self.__class__(self._format(*real_mapping), *new_holes)
 
@@ -347,8 +349,10 @@ class PartialString:
         """Partially apply a list, implicitly mapped from self.holes."""
         return self.pformat(dict(zip(self.holes, args)))
 
-    def format(self, mapping={}):
+    def format(self, mapping=None):
         """Fully apply a mapping, returning a string."""
+        if mapping is None:
+            mapping = {}
         real_mapping, new_holes = self._pformat(mapping, False)
         if new_holes:
             raise ValueError("not all holes filled: %r" % new_holes)



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/6a29f49d834416426261882de7df87635f4e618c...26d9a39f142476ed00586e2ff4d0203f1bf101c0

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/6a29f49d834416426261882de7df87635f4e618c...26d9a39f142476ed00586e2ff4d0203f1bf101c0
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/20200810/064e6d44/attachment.htm>


More information about the rb-commits mailing list