[Reproducible-commits] [debbindiff] 08/10: Add support for comparing bzip2
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 09ad75cde48d1bfe08bc45ccef69011700cd5bfb
Author: Jérémy Bobbio <lunar at debian.org>
Date: Mon Sep 29 18:32:14 2014 +0200
Add support for comparing bzip2
---
debbindiff/comparators/__init__.py | 2 ++
debbindiff/comparators/bzip2.py | 46 ++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 82866d9..e689827 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -23,6 +23,7 @@ import re
from debbindiff import logger
from debbindiff.difference import Difference, get_source
from debbindiff.comparators.binary import compare_binary_files
+from debbindiff.comparators.bzip2 import compare_bzip2_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
@@ -57,6 +58,7 @@ COMPARATORS = [
(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),
+ (r'^application/x-bzip2(;|$)', r'\.bzip2$', compare_bzip2_files),
]
def compare_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/bzip2.py b/debbindiff/comparators/bzip2.py
new file mode 100644
index 0000000..ff22ada
--- /dev/null
+++ b/debbindiff/comparators/bzip2.py
@@ -0,0 +1,46 @@
+# -*- 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 os.path
+import subprocess
+import debbindiff.comparators
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory
+from debbindiff.difference import get_source
+
+ at contextmanager
+def decompress_bzip2(path):
+ with make_temp_directory() as temp_dir:
+ if path.endswith('.bz2'):
+ temp_path = os.path.join(temp_dir, os.path.basename(path[:-4]))
+ else:
+ temp_path = os.path.join(temp_dir, "%s-content" % path)
+ with open(temp_path, 'wb') as temp_file:
+ subprocess.check_call(
+ ["bzip2", "--decompress", "--stdout", path],
+ shell=False, stdout=temp_file, stderr=None)
+ yield temp_path
+
+ at binary_fallback
+def compare_bzip2_files(path1, path2, source=None):
+ with decompress_bzip2(path1) as new_path1:
+ with decompress_bzip2(path2) as new_path2:
+ return debbindiff.comparators.compare_files(
+ new_path1, new_path2,
+ source=get_source(new_path1, new_path2))
--
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