[Reproducible-commits] [debbindiff] 06/10: Add support for comparing .deb
Jérémy Bobbio
lunar at moszumanska.debian.org
Mon Sep 29 18:29:23 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 6d38cdbdf07ee87db7efb8e33cab854bf3f4da63
Author: Jérémy Bobbio <lunar at debian.org>
Date: Mon Sep 29 18:13:52 2014 +0200
Add support for comparing .deb
---
debbindiff/comparators/__init__.py | 8 +++--
debbindiff/comparators/deb.py | 61 ++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index d72e981..2ad4ebf 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -24,6 +24,7 @@ from debbindiff import logger
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.text import compare_text_files
from debbindiff.comparators.tar import compare_tar_files
from debbindiff.comparators.xz import compare_xz_files
@@ -50,9 +51,10 @@ def compare_unknown(path1, path2, source=None):
return compare_binary_files(path1, path2, source)
COMPARATORS = [
- (None, r'\.changes$', compare_changes_files),
- (r'^application/x-xz(;|$)', r'\.xz$', compare_xz_files),
- (r'^application/x-tar(;|$)', r'\.tar$', compare_tar_files),
+ (None, r'\.changes$', compare_changes_files),
+ (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),
]
def compare_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/deb.py b/debbindiff/comparators/deb.py
new file mode 100644
index 0000000..11d30e4
--- /dev/null
+++ b/debbindiff/comparators/deb.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 debian.arfile import ArFile
+from debbindiff import logger
+from debbindiff.difference import Difference
+import debbindiff.comparators
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory
+
+def get_ar_content(path):
+ return subprocess.check_output(['ar', 'tv', path], shell=False)
+
+ at binary_fallback
+def compare_deb_files(path1, path2, source=None):
+ differences = []
+ # look up differences in content
+ ar1 = ArFile(filename=path1)
+ ar2 = ArFile(filename=path2)
+ with make_temp_directory() as temp_dir1:
+ with make_temp_directory() as temp_dir2:
+ logger.debug('content1 %s' % (ar1.getnames(),))
+ logger.debug('content2 %s' % (ar2.getnames(),))
+ for name in sorted(set(ar1.getnames()).intersection(ar2.getnames())):
+ logger.debug('extract member %s' % (name,))
+ member1 = ar1.getmember(name)
+ member2 = ar2.getmember(name)
+ in_path1 = os.path.join(temp_dir1, name)
+ in_path2 = os.path.join(temp_dir2, name)
+ with open(in_path1, 'w') as f1:
+ f1.write(member1.read())
+ with open(in_path2, 'w') as f2:
+ f2.write(member2.read())
+ differences.extend(
+ debbindiff.comparators.compare_files(
+ in_path1, in_path2, source=name))
+ os.unlink(in_path1)
+ os.unlink(in_path2)
+ # look up differences in file list and file metadata
+ content1 = get_ar_content(path1)
+ content2 = get_ar_content(path2)
+ if content1 != content2:
+ differences.append(Difference(content1.splitlines(1), content2.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