[Reproducible-commits] [debbindiff] 06/09: Add support for comparing directories

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Feb 15 11:29:55 UTC 2015


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

lunar pushed a commit to annotated tag 9
in repository debbindiff.

commit 8917caf4923cc8ffcbf04fab4e6f432bb0d09397
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sun Feb 15 10:28:37 2015 +0000

    Add support for comparing directories
---
 debbindiff/comparators/__init__.py  |  3 +++
 debbindiff/comparators/directory.py | 47 +++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 41f805d..3edfe49 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -28,6 +28,7 @@ from debbindiff.comparators.bzip2 import compare_bzip2_files
 from debbindiff.comparators.changes import compare_changes_files
 from debbindiff.comparators.cpio import compare_cpio_files
 from debbindiff.comparators.deb import compare_deb_files, compare_md5sums_files
+from debbindiff.comparators.directory import compare_directories
 from debbindiff.comparators.elf import \
     compare_elf_files, compare_static_lib_files
 from debbindiff.comparators.fonts import compare_ttf_files
@@ -95,6 +96,8 @@ SMALL_FILE_THRESHOLD = 65536 # 64 kiB
 
 
 def compare_files(path1, path2, source=None):
+    if os.path.isdir(path1) and os.path.isdir(path2):
+        return compare_directories(path1, path2)
     if not os.path.isfile(path1):
         logger.critical("%s is not a file", path1)
         sys.exit(2)
diff --git a/debbindiff/comparators/directory.py b/debbindiff/comparators/directory.py
new file mode 100644
index 0000000..0e46763
--- /dev/null
+++ b/debbindiff/comparators/directory.py
@@ -0,0 +1,47 @@
+# -*- 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
+from debbindiff.difference import Difference
+import debbindiff.comparators
+
+
+def ls(path):
+    return subprocess.check_output(['ls', '-l', path], shell=False).decode('utf-8')
+
+
+def compare_directories(path1, path2):
+    differences = []
+    for name in sorted(set(os.listdir(path1)).intersection(os.listdir(path2))):
+        in_path1 = os.path.join(path1, name)
+        in_path2 = os.path.join(path2, name)
+        differences.extend(debbindiff.comparators.compare_files(
+                               in_path1, in_path2, source=name))
+    ls1 = ls(path1)
+    ls2 = ls(path2)
+    if ls1 != ls2:
+        differences.append(Difference(
+            ls1.splitlines(1), ls2.splitlines(2),
+            path1, path2, source="ls -l"))
+    if differences:
+        d = Difference(None, None, path1, path2)
+        d.add_details(differences)
+        return [d]
+    return []

-- 
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