[Reproducible-commits] [debbindiff] 01/02: Add support for ISO9660 images

Jérémy Bobbio lunar at moszumanska.debian.org
Tue Apr 21 09:35:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository debbindiff.

commit 8aa5b39a19a88f1ca8dbb8cef1d2936e2c1b8e20
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Tue Apr 21 11:27:33 2015 +0200

    Add support for ISO9660 images
---
 debbindiff/comparators/__init__.py |  2 +
 debbindiff/comparators/iso9660.py  | 98 ++++++++++++++++++++++++++++++++++++++
 debbindiff/difference.py           |  8 +++-
 3 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index f31fd18..8a7e8ad 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -35,6 +35,7 @@ from debbindiff.comparators.fonts import compare_ttf_files
 from debbindiff.comparators.gettext import compare_mo_files
 from debbindiff.comparators.gzip import compare_gzip_files
 from debbindiff.comparators.haskell import compare_hi_files
+from debbindiff.comparators.iso9660 import compare_iso9660_files
 from debbindiff.comparators.pdf import compare_pdf_files
 from debbindiff.comparators.png import compare_png_files
 from debbindiff.comparators.rpm import compare_rpm_files
@@ -94,6 +95,7 @@ COMPARATORS = [
     (r'^application/postscript; charset=(?P<encoding>[a-z0-9-]+)$', None, compare_text_files),
     (None, r'\.squashfs$', compare_squashfs_files),
     (None, r'\.a$', compare_static_lib_files),
+    (r'^application/x-iso9660-image(;|$)', None, compare_iso9660_files)
     ]
 
 SMALL_FILE_THRESHOLD = 65536 # 64 kiB
diff --git a/debbindiff/comparators/iso9660.py b/debbindiff/comparators/iso9660.py
new file mode 100644
index 0000000..e327ec2
--- /dev/null
+++ b/debbindiff/comparators/iso9660.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# debbindiff is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# debbindiff is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with debbindiff.  If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+import subprocess
+import debbindiff.comparators
+from debbindiff import logger, tool_required
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory, Command
+from debbindiff.difference import Difference
+
+
+ at tool_required('isoinfo')
+def get_iso9660_names(path):
+    # We always use RockRidge for names. Let's see if this proves
+    # problematic later
+    cmd = ['isoinfo', '-R', '-f', '-i', path]
+    return subprocess.check_output(cmd, shell=False).strip().split('\n')
+
+
+class ISO9660PVD(Command):
+    @tool_required('isoinfo')
+    def cmdline(self):
+        return ['isoinfo', '-d', '-i', self.path]
+
+
+class ISO9660Listing(Command):
+    def __init__(self, path, extension=None, *args, **kwargs):
+        self._extension = extension
+        super(ISO9660Listing, self).__init__(path, *args, **kwargs)
+
+    @tool_required('isoinfo')
+    def cmdline(self):
+        cmd = ['isoinfo', '-l', '-i', self.path]
+        if self._extension == 'joliet':
+            cmd.extend(['-J', 'iso-8859-15'])
+        elif self._extension == 'rockridge':
+            cmd.extend(['-R'])
+        return cmd
+
+    def filter(self, line):
+        if self._extension == 'joliet':
+            return line.decode('iso-8859-15').encode('utf-8')
+        else:
+            return line
+
+ at tool_required('isoinfo')
+def extract_from_iso9660(image_path, in_path, dest):
+    # Use RockRidge, same as get_iso9660_names
+    cmd = ['isoinfo', '-i', image_path, '-R', '-x', in_path]
+    return subprocess.check_call(cmd, shell=False, stdout=dest)
+
+
+ at binary_fallback
+def compare_iso9660_files(path1, path2, source=None):
+    differences = []
+
+    # compare metadata
+    difference = Difference.from_command(ISO9660PVD, path1, path2)
+    if difference:
+        differences.append(difference)
+    for extension in (None, 'joliet', 'rockridge'):
+        difference = Difference.from_command(ISO9660Listing, path1, path2, command_args=(extension,))
+        if difference:
+            differences.append(difference)
+
+    # compare files contained in image
+    files1 = get_iso9660_names(path1)
+    files2 = get_iso9660_names(path2)
+    with make_temp_directory() as temp_dir1:
+        with make_temp_directory() as temp_dir2:
+            for name in sorted(set(files1).intersection(files2)):
+                logger.debug('extract file %s' % name)
+                in_path1 = os.path.join(temp_dir1, os.path.basename(name))
+                in_path2 = os.path.join(temp_dir2, os.path.basename(name))
+                with open(in_path1, 'w') as dest:
+                    extract_from_iso9660(path1, name, dest)
+                with open(in_path2, 'w') as dest:
+                    extract_from_iso9660(path2, name, dest)
+                differences.extend(debbindiff.comparators.compare_files(
+                    in_path1, in_path2, source=name))
+
+    return differences
diff --git a/debbindiff/difference.py b/debbindiff/difference.py
index 03aa309..845cf58 100644
--- a/debbindiff/difference.py
+++ b/debbindiff/difference.py
@@ -317,8 +317,12 @@ class Difference(object):
 
     @staticmethod
     def from_command(cls, path1, path2, *args, **kwargs):
-        command1 = cls(path1)
-        command2 = cls(path2)
+        command_args = []
+        if 'command_args' in kwargs:
+            command_args = kwargs['command_args']
+            del kwargs['command_args']
+        command1 = cls(path1, *command_args)
+        command2 = cls(path2, *command_args)
         if 'source' not in kwargs:
             kwargs['source'] = ' '.join(map(lambda x: '{}' if x == command1.path else x, command1.cmdline()))
         difference = Difference.from_feeder(make_feeder_from_command(command1),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git



More information about the Reproducible-commits mailing list