[Reproducible-commits] [debbindiff] 12/19: Convert elf comparator to Command class

Jérémy Bobbio lunar at moszumanska.debian.org
Tue Mar 31 14:59:29 UTC 2015


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

lunar pushed a commit to branch pu/feed-diff
in repository debbindiff.

commit 73ff6742e189ba1159b0416fa8a8288d0a08adcd
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Mon Mar 30 16:30:59 2015 +0200

    Convert elf comparator to Command class
---
 debbindiff/comparators/elf.py | 63 +++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 36 deletions(-)

diff --git a/debbindiff/comparators/elf.py b/debbindiff/comparators/elf.py
index 66b2e49..14e284b 100644
--- a/debbindiff/comparators/elf.py
+++ b/debbindiff/comparators/elf.py
@@ -21,59 +21,50 @@ import os.path
 import re
 import subprocess
 from debbindiff import tool_required
-from debbindiff.comparators.utils import binary_fallback, get_ar_content
+from debbindiff.comparators.utils import binary_fallback, get_ar_content, Command
 from debbindiff.difference import Difference
 
 
- at tool_required('readelf')
-def readelf_all(path):
-    output = subprocess.check_output(
-        ['readelf', '--all', path],
-        shell=False, stderr=subprocess.PIPE).decode('ascii')
-    # the full path can appear in the output, we need to remove it
-    return re.sub(re.escape(path), os.path.basename(path), output)
+class ReadelfAll(Command):
+    @tool_required('readelf')
+    def cmdline(self):
+        return ['readelf', '--all', self.path]
 
+    def filter(self, line):
+        # the full path can appear in the output, we need to remove it
+        return line.replace(self.path, os.path.basename(self.path))
 
- at tool_required('readelf')
-def readelf_debug_dump(path):
-    output = subprocess.check_output(
-        ['readelf', '--debug-dump', path],
-        shell=False, stderr=subprocess.PIPE).decode('ascii')
-    # the full path can appear in the output, we need to remove it
-    return re.sub(re.escape(path), os.path.basename(path), output)
 
+class ReadelfDebugDump(Command):
+    @tool_required('readelf')
+    def cmdline(self):
+        return ['readelf', '--debug-dump', self.path]
 
- at tool_required('objdump')
-def objdump_disassemble(path):
-    output = subprocess.check_output(
-        ['objdump', '--disassemble', '--full-contents', path],
-        shell=False, stderr=subprocess.PIPE)
-    # the full path appears in the output, we need to remove it
-    return re.sub(re.escape(path), os.path.basename(path), output).decode('ascii')
+    def filter(self, line):
+        # the full path can appear in the output, we need to remove it
+        return line.replace(self.path, os.path.basename(self.path))
 
 
+class ObjdumpDisassemble(Command):
+    @tool_required('objdump')
+    def cmdline(self):
+        return ['objdump', '--disassemble', '--full-contents', self.path]
+
+    def filter(self, line):
+        # the full path can appear in the output, we need to remove it
+        return line.replace(self.path, os.path.basename(self.path))
+
 # this one is not wrapped with binary_fallback and is used
 # by both compare_elf_files and compare_static_lib_files
 def _compare_elf_data(path1, path2, source=None):
     differences = []
-    all1 = readelf_all(path1)
-    all2 = readelf_all(path2)
-    difference = Difference.from_unicode(
-                     all1, all2, path1, path2, source='readelf --all')
+    difference = Difference.from_command(ReadelfAll, path1, path2)
     if difference:
         differences.append(difference)
-    debug_dump1 = readelf_debug_dump(path1)
-    debug_dump2 = readelf_debug_dump(path2)
-    difference = Difference.from_unicode(
-                     debug_dump1, debug_dump2,
-                     path1, path2, source='readelf --debug-dump')
+    difference = Difference.from_command(ReadelfDebugDump, path1, path2)
     if difference:
         differences.append(difference)
-    objdump1 = objdump_disassemble(path1)
-    objdump2 = objdump_disassemble(path2)
-    difference = Difference.from_unicode(
-                     objdump1, objdump2,
-                     path1, path2, source='objdump --disassemble --full-contents')
+    difference = Difference.from_command(ObjdumpDisassemble, path1, path2)
     if difference:
         differences.append(difference)
     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