[Reproducible-commits] [debbindiff] 05/09: Add support for comparing zip and jar files
Jérémy Bobbio
lunar at moszumanska.debian.org
Tue Sep 30 15:10:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 10967862602fea0ce76b045c2667c96bb0255be3
Author: Jérémy Bobbio <lunar at debian.org>
Date: Tue Sep 30 12:07:07 2014 +0200
Add support for comparing zip and jar files
---
debbindiff/comparators/__init__.py | 3 ++
debbindiff/comparators/zip.py | 61 ++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 1e7dae7..ed44dd3 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -20,6 +20,7 @@
import magic
import os.path
import re
+import sys
from debbindiff import logger
from debbindiff.difference import Difference, get_source
from debbindiff.comparators.binary import compare_binary_files
@@ -33,6 +34,7 @@ from debbindiff.comparators.haskell import compare_hi_files
from debbindiff.comparators.text import compare_text_files
from debbindiff.comparators.tar import compare_tar_files
from debbindiff.comparators.xz import compare_xz_files
+from debbindiff.comparators.zip import compare_zip_files
def guess_mime_type(path):
if not hasattr(guess_mime_type, 'mimedb'):
@@ -62,6 +64,7 @@ COMPARATORS = [
(None, r'\.mo$', compare_mo_files),
(r'^application/x-xz(;|$)', r'\.xz$', compare_xz_files),
(r'^application/x-tar(;|$)', r'\.tar$', compare_tar_files),
+ (r'^application/zip(;|$)', r'\.(zip|jar)$', compare_zip_files),
(r'^application/x-debian-package(;|$)', r'\.deb$', compare_deb_files),
(r'^application/x-gzip(;|$)', r'\.gz$', compare_gzip_files),
(r'^application/x-bzip2(;|$)', r'\.bzip2$', compare_bzip2_files),
diff --git a/debbindiff/comparators/zip.py b/debbindiff/comparators/zip.py
new file mode 100644
index 0000000..ab0a83e
--- /dev/null
+++ b/debbindiff/comparators/zip.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2014 Jérémy Bobbio <lunar at debian.org>
+#
+# debdindiff 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
+from zipfile import ZipFile
+from debbindiff import logger
+from debbindiff.difference import Difference
+import debbindiff.comparators
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory
+
+def get_zipinfo(path):
+ output = subprocess.check_output(['zipinfo', path], shell=False)
+ # the full path appears in the output, we need to remove it
+ return re.sub(re.escape(path), os.path.basename(path), output)
+
+ at binary_fallback
+def compare_zip_files(path1, path2, source=None):
+ differences = []
+ with ZipFile(path1, 'r') as zip1:
+ with ZipFile(path2, 'r') as zip2:
+ # look up differences in content
+ with make_temp_directory() as temp_dir1:
+ with make_temp_directory() as temp_dir2:
+ for name in sorted(set(zip1.namelist()).intersection(zip2.namelist())):
+ # skip directories
+ if name.endswith('/'):
+ continue
+ logger.debug('extract member %s' % (name,))
+ zip1.extract(name, temp_dir1)
+ zip2.extract(name, temp_dir2)
+ in_path1 = os.path.join(temp_dir1, name)
+ in_path2 = os.path.join(temp_dir2, name)
+ differences.extend(
+ debbindiff.comparators.compare_files(
+ in_path1, in_path2,
+ source=name))
+ os.unlink(in_path1)
+ os.unlink(in_path2)
+ # look up differences in metadata
+ zipinfo1 = get_zipinfo(path1)
+ zipinfo2 = get_zipinfo(path2)
+ if zipinfo1 != zipinfo2:
+ differences.append(Difference(zipinfo1.splitlines(1), zipinfo2.splitlines(1), path1, path2, source="metadata"))
+ return differences
--
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