[Reproducible-commits] [debbindiff] 07/10: Add support for comparing gzip files

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Sep 29 18:29:24 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 d88ef9ce81a9bc1470ff8f0478c60397e2a43c91
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Mon Sep 29 18:14:06 2014 +0200

    Add support for comparing gzip files
---
 debbindiff/comparators/__init__.py |  2 ++
 debbindiff/comparators/gzip.py     | 58 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 2ad4ebf..82866d9 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -25,6 +25,7 @@ from debbindiff.difference import Difference, get_source
 from debbindiff.comparators.binary import compare_binary_files
 from debbindiff.comparators.changes import compare_changes_files
 from debbindiff.comparators.deb import compare_deb_files
+from debbindiff.comparators.gzip import compare_gzip_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
@@ -55,6 +56,7 @@ COMPARATORS = [
         (r'^application/x-xz(;|$)',             r'\.xz$',      compare_xz_files),
         (r'^application/x-tar(;|$)',            r'\.tar$',     compare_tar_files),
         (r'^application/x-debian-package(;|$)', r'\.deb$',     compare_deb_files),
+        (r'^application/x-gzip(;|$)',           r'\.gz$',      compare_gzip_files),
     ]
 
 def compare_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/gzip.py b/debbindiff/comparators/gzip.py
new file mode 100644
index 0000000..2923d56
--- /dev/null
+++ b/debbindiff/comparators/gzip.py
@@ -0,0 +1,58 @@
+# -*- 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/>.
+
+from contextlib import contextmanager
+import gzip
+import subprocess
+import os.path
+import debbindiff.comparators
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory
+from debbindiff.difference import Difference, get_source
+
+ at contextmanager
+def decompress_gzip(path):
+    with make_temp_directory() as temp_dir:
+        if path.endswith('.gz'):
+            temp_path = os.path.join(temp_dir, os.path.basename(path[:-3]))
+        else:
+            temp_path = os.path.join(temp_dir, "%s-content" % path)
+        with open(temp_path, 'wb') as temp_file:
+            subprocess.check_call(
+                ["gzip", "--decompress", "--stdout", path],
+                shell=False, stdout=temp_file, stderr=None)
+            yield temp_path
+
+def get_gzip_metadata(path):
+    return subprocess.check_output(['file', '--brief', path])
+
+ at binary_fallback
+def compare_gzip_files(path1, path2, source=None):
+    differences = []
+    # check metadata
+    metadata1 = get_gzip_metadata(path1)
+    metadata2 = get_gzip_metadata(path2)
+    if metadata1 != metadata2:
+        differences.append(Difference(metadata1.splitlines(1), metadata2.splitlines(1), path1, path2, source='metadata'))
+    # check content
+    with decompress_gzip(path1) as new_path1:
+        with decompress_gzip(path2) as new_path2:
+            differences.extend(debbindiff.comparators.compare_files(
+                new_path1, new_path2,
+                source=get_source(new_path1, new_path2)))
+    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