[Git][reproducible-builds/diffoscope][master] Compare .zip file comments with zipnote. (Closes: #901757)

Chris Lamb gitlab at salsa.debian.org
Thu Dec 6 22:29:05 CET 2018


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
28695191 by Chris Lamb at 2018-12-06T21:17:46Z
Compare .zip file comments with zipnote. (Closes: #901757)

- - - - -


7 changed files:

- debian/tests/control
- diffoscope/comparators/zip.py
- diffoscope/external_tools.py
- tests/comparators/test_zip.py
- + tests/data/comment_zipinfo_expected_diff
- + tests/data/test_comment1.zip
- + tests/data/test_comment2.zip


Changes:

=====================================
debian/tests/control
=====================================
@@ -7,7 +7,7 @@
 #   $ mv debian/tests/control.tmp debian/tests/control
 
 Tests: pytest-with-recommends
-Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
+Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, zip, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
 
 Tests: pytest
 Depends: diffoscope, python3-pytest, file


=====================================
diffoscope/comparators/zip.py
=====================================
@@ -57,6 +57,43 @@ class ZipinfoVerbose(Zipinfo):
         return ['zipinfo', '-v', self.path]
 
 
+class Zipnote(Command):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+        self.flag = False
+
+    @tool_required('zipnote')
+    def cmdline(self):
+        return ['zipnote', self.path]
+
+    def filter(self, line):
+        """
+        Example output from zipnote(1):
+
+            @ foo
+            hello
+            @ (comment above this line)
+            @ (zip file comment below this line)
+            goodbye
+        """
+
+        if line == b'@ (zip file comment below this line)\n':
+            self.flag = True
+            return b'Zip file comment: '
+
+        if line == b'@ (comment above this line)\n':
+            self.flag = False
+            return b'\n\n'  # spacer
+
+        if line.startswith(b'@ '):
+            filename = line[2:-1].decode()
+            self.flag = True
+            return "Filename: {}\nComment: ".format(filename).encode()
+
+        return line[:-1] if self.flag else b''
+
+
 class BsdtarVerbose(Command):
     @tool_required('bsdtar')
     def cmdline(self):
@@ -125,10 +162,15 @@ class ZipFile(File):
         r'^(Zip archive|Java archive|EPUB document|OpenDocument (Text|Spreadsheet|Presentation|Drawing|Formula|Template|Text Template))\b')
 
     def compare_details(self, other, source=None):
+        differences = []
         zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
             Difference.from_command(ZipinfoVerbose, self.path, other.path) or \
             Difference.from_command(BsdtarVerbose, self.path, other.path)
-        return [zipinfo_difference]
+        zipnote_difference = Difference.from_command(Zipnote, self.path, other.path)
+        for x in (zipinfo_difference, zipnote_difference):
+            if x is not None:
+                differences.append(x)
+        return differences
 
 
 class MozillaZipCommandMixin(object):


=====================================
diffoscope/external_tools.py
=====================================
@@ -267,6 +267,9 @@ EXTERNAL_TOOLS = {
         'arch': 'unzip',
         'FreeBSD': 'unzip',
     },
+    'zipnote': {
+        'debian': 'zip',
+    },
     'procyon': {
         'debian': 'procyon-decompiler',
     },


=====================================
tests/comparators/test_zip.py
=====================================
@@ -33,6 +33,8 @@ encrypted_zip1 = load_fixture('encrypted1.zip')
 encrypted_zip2 = load_fixture('encrypted2.zip')
 mozzip1 = load_fixture('test1.mozzip')
 mozzip2 = load_fixture('test2.mozzip')
+test_comment1 = load_fixture('test_comment1.zip')
+test_comment2 = load_fixture('test_comment2.zip')
 
 
 def test_identification(zip1):
@@ -117,3 +119,14 @@ def test_mozzip_compare_non_existing(monkeypatch, mozzip1):
 def test_encrypted(encrypted_zip1, encrypted_zip2):
     difference = encrypted_zip1.compare(encrypted_zip2)
     assert difference is not None
+
+
+ at pytest.fixture
+def comment_differences(test_comment1, test_comment2):
+    return test_comment1.compare(test_comment2).details
+
+
+ at skip_unless_tools_exist('zipnote')
+def test_commented(comment_differences):
+    expected_diff = get_data('comment_zipinfo_expected_diff')
+    assert comment_differences[1].unified_diff == expected_diff


=====================================
tests/data/comment_zipinfo_expected_diff
=====================================
@@ -0,0 +1,7 @@
+@@ -1,4 +1,4 @@
+ Filename: foo
+-Comment: 
++Comment: hello
+ 
+-Zip file comment: 
++Zip file comment: goodbye


=====================================
tests/data/test_comment1.zip
=====================================
Binary files /dev/null and b/tests/data/test_comment1.zip differ


=====================================
tests/data/test_comment2.zip
=====================================
Binary files /dev/null and b/tests/data/test_comment2.zip differ



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

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/28695191147fce66695e28503197d3656e43c1f1
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/20181206/1b5eb583/attachment.html>


More information about the rb-commits mailing list