[Reproducible-commits] [diffoscope] 05/21: XXX
Joachim Breitner
nomeata at moszumanska.debian.org
Thu Dec 3 15:05:04 UTC 2015
This is an automated email from the git hooks/post-receive script.
nomeata pushed a commit to branch pu/parallel2
in repository diffoscope.
commit 31a4639fcd689f1821b944801d368dc7fb93d247
Author: Jérémy Bobbio <lunar at debian.org>
Date: Tue Oct 6 15:44:56 2015 +0000
XXX
---
diffoscope/comparators/binary.py | 17 +++++++++++------
diffoscope/comparators/bzip2.py | 3 ---
diffoscope/comparators/cpio.py | 6 +-----
diffoscope/comparators/deb.py | 5 +----
diffoscope/comparators/debian.py | 16 +++++-----------
diffoscope/comparators/elf.py | 18 ++++++------------
diffoscope/comparators/fonts.py | 2 +-
diffoscope/comparators/gettext.py | 2 +-
diffoscope/comparators/gzip.py | 6 +-----
diffoscope/comparators/haskell.py | 2 +-
diffoscope/comparators/iso9660.py | 12 +++---------
diffoscope/comparators/java.py | 2 +-
diffoscope/comparators/mono.py | 2 +-
diffoscope/comparators/pdf.py | 6 ++----
diffoscope/comparators/png.py | 2 +-
diffoscope/comparators/rpm.py | 5 +----
diffoscope/comparators/sqlite.py | 2 +-
diffoscope/comparators/squashfs.py | 7 ++-----
diffoscope/comparators/tar.py | 5 +----
diffoscope/comparators/xz.py | 3 ---
diffoscope/comparators/zip.py | 6 +-----
diffoscope/difference.py | 14 +++++++++++---
22 files changed, 53 insertions(+), 90 deletions(-)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index aa74277..f313a5a 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -22,6 +22,7 @@ from binascii import hexlify
from contextlib import contextmanager
from functools import wraps
from io import StringIO
+import itertools
import os
import os.path
import re
@@ -128,7 +129,7 @@ class File(object, metaclass=ABCMeta):
if not hasattr(self.__class__, 'CONTAINER_CLASS'):
if hasattr(self, '_other_file'):
return self._other_file.__class__.CONTAINER_CLASS(self)
- raise NotImplemented('Not a container.')
+ return None
if not hasattr(self, '_as_container'):
logger.debug('instanciating %s for %s', self.__class__.CONTAINER_CLASS, self)
self._as_container = self.__class__.CONTAINER_CLASS(self)
@@ -172,13 +173,17 @@ class File(object, metaclass=ABCMeta):
def compare_bytes(self, other, source=None):
return compare_binary_files(self, other, source)
+ def _details_generators(self, other, source):
+ if hasattr(self, 'compare_details'):
+ yield self.compare_details(other, source)
+ if self.as_container:
+ yield self.as_container.compare(other.as_container)
+
def _compare_using_details(self, other, source):
- details = [d for d in self.compare_details(other, source) if d is not None]
+ details = list(filter(None, itertools.chain.from_iterable(self._details_generators(other, source))))
if len(details) == 0:
return None
- difference = Difference(None, self.name, other.name, source=source)
- difference.add_details(details)
- return difference
+ return Difference.from_details(self.name, other.name, details, source=source)
@tool_required('cmp')
def has_same_content_as(self, other):
@@ -196,7 +201,7 @@ class File(object, metaclass=ABCMeta):
# To be specialized directly, or by implementing compare_details
def compare(self, other, source=None):
- if hasattr(self, 'compare_details'):
+ if hasattr(self, 'compare_details') or self.as_container:
try:
difference = self._compare_using_details(other, source)
# no differences detected inside? let's at least do a binary diff
diff --git a/diffoscope/comparators/bzip2.py b/diffoscope/comparators/bzip2.py
index 6429847..ff63ef1 100644
--- a/diffoscope/comparators/bzip2.py
+++ b/diffoscope/comparators/bzip2.py
@@ -57,6 +57,3 @@ class Bzip2File(File):
@staticmethod
def recognizes(file):
return Bzip2File.RE_FILE_TYPE.match(file.magic_file_type)
-
- def compare_details(self, other, source=None):
- return self.as_container.compare(other.as_container)
diff --git a/diffoscope/comparators/cpio.py b/diffoscope/comparators/cpio.py
index 536e80c..e79d88e 100644
--- a/diffoscope/comparators/cpio.py
+++ b/diffoscope/comparators/cpio.py
@@ -41,8 +41,4 @@ class CpioFile(File):
return CpioFile.RE_FILE_TYPE.search(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(
- CpioContent, self.path, other.path, source="file list"))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_command(CpioContent, self.path, other.path, source="file list")
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 8043389..404a20b 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -123,7 +123,4 @@ class DebDataTarFile(File):
isinstance(file.container.source.container.source, DebFile)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(TarListing, self.path, other.path))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_command(TarListing, self.path, other.path)
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index 703804d..1ff2a50 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -104,8 +104,6 @@ class DebControlFile(File):
return self._deb822
def compare_details(self, other, source=None):
- differences = []
-
for field in sorted(set(self.deb822.keys()).union(set(other.deb822.keys()))):
if field.startswith('Checksums-') or field == 'Files':
continue
@@ -115,16 +113,12 @@ class DebControlFile(File):
other_value = ''
if field in other.deb822:
other_value = other.deb822.get_as_string(field).lstrip()
- differences.append(Difference.from_text(
- my_value, other_value,
- self.path, other.path, source=field))
+ yield Difference.from_text(my_value, other_value,
+ self.path, other.path, source=field)
# compare Files as string
- differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
- other.deb822.get_as_string('Files'),
- self.path, other.path, source='Files'))
- differences.extend(self.as_container.compare(other.as_container))
-
- return differences
+ yield Difference.from_text(self.deb822.get_as_string('Files'),
+ other.deb822.get_as_string('Files'),
+ self.path, other.path, source='Files')
class DotChangesFile(DebControlFile):
RE_FILE_EXTENSION = re.compile(r'\.changes$')
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index 30f6953..59c63e8 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -77,11 +77,9 @@ class ObjdumpDisassemble(Command):
return line
def _compare_elf_data(path1, path2):
- differences = []
- differences.append(Difference.from_command(ReadelfAll, path1, path2))
- differences.append(Difference.from_command(ReadelfDebugDump, path1, path2))
- differences.append(Difference.from_command(ObjdumpDisassemble, path1, path2))
- return differences
+ yield Difference.from_command(ReadelfAll, path1, path2)
+ yield Difference.from_command(ReadelfDebugDump, path1, path2)
+ yield Difference.from_command(ObjdumpDisassemble, path1, path2)
class ElfFile(File):
RE_FILE_TYE = re.compile(r'^ELF ')
@@ -91,7 +89,7 @@ class ElfFile(File):
return ElfFile.RE_FILE_TYE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- return _compare_elf_data(self.path, other.path)
+ yield from _compare_elf_data(self.path, other.path)
class StaticLibFile(File):
RE_FILE_TYPE = re.compile(r'\bar archive\b')
@@ -102,11 +100,7 @@ class StaticLibFile(File):
return StaticLibFile.RE_FILE_TYPE.search(file.magic_file_type) and StaticLibFile.RE_FILE_EXTENSION.search(file.name)
def compare_details(self, other, source=None):
- differences = []
- # look up differences in metadata
content1 = get_ar_content(self.path)
content2 = get_ar_content(other.path)
- differences.append(Difference.from_text(
- content1, content2, self.path, other.path, source="metadata"))
- differences.extend(_compare_elf_data(self.path, other.path))
- return differences
+ yield Difference.from_text(content1, content2, self.path, other.path, source="metadata")
+ yield from _compare_elf_data(self.path, other.path)
diff --git a/diffoscope/comparators/fonts.py b/diffoscope/comparators/fonts.py
index 187655a..fd4ae93 100644
--- a/diffoscope/comparators/fonts.py
+++ b/diffoscope/comparators/fonts.py
@@ -41,4 +41,4 @@ class TtfFile(File):
return TtfFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- return [Difference.from_command(Showttf, self.path, other.path)]
+ yield Difference.from_command(Showttf, self.path, other.path)
diff --git a/diffoscope/comparators/gettext.py b/diffoscope/comparators/gettext.py
index b739900..29252fa 100644
--- a/diffoscope/comparators/gettext.py
+++ b/diffoscope/comparators/gettext.py
@@ -64,4 +64,4 @@ class MoFile(File):
return MoFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- return [Difference.from_command(Msgunfmt, self.path, other.path)]
+ yield Difference.from_command(Msgunfmt, self.path, other.path)
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index f9f585b..6d1dac5 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -59,8 +59,4 @@ class GzipFile(object):
return GzipFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_text(
- self.magic_file_type, other.magic_file_type, self, other, source='metadata'))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')
diff --git a/diffoscope/comparators/haskell.py b/diffoscope/comparators/haskell.py
index 7bd4025..f7b0e5c 100644
--- a/diffoscope/comparators/haskell.py
+++ b/diffoscope/comparators/haskell.py
@@ -83,4 +83,4 @@ class HiFile(File):
return True
def compare_details(self, other, source=None):
- return [Difference.from_command(ShowIface, self.path, other.path)]
+ yield Difference.from_command(ShowIface, self.path, other.path)
diff --git a/diffoscope/comparators/iso9660.py b/diffoscope/comparators/iso9660.py
index f194fef..235a18b 100644
--- a/diffoscope/comparators/iso9660.py
+++ b/diffoscope/comparators/iso9660.py
@@ -70,13 +70,7 @@ class Iso9660File(File):
return Iso9660File.RE_FILE_TYPE.search(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(ISO9660PVD, self.path, other.path))
- differences.append(Difference.from_command(ISO9660Listing, self.path, other.path))
+ yield Difference.from_command(ISO9660PVD, self.path, other.path)
+ yield Difference.from_command(ISO9660Listing, self.path, other.path)
for extension in ('joliet', 'rockridge'):
- try:
- differences.append(Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,)))
- except subprocess.CalledProcessError:
- pass # probably no joliet or rockridge data
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,), suppress_errors=(subprocess.CalledProcessError,))
diff --git a/diffoscope/comparators/java.py b/diffoscope/comparators/java.py
index f8b6b5e..edea2f2 100644
--- a/diffoscope/comparators/java.py
+++ b/diffoscope/comparators/java.py
@@ -49,4 +49,4 @@ class ClassFile(File):
return ClassFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- return [Difference.from_command(Javap, self.path, other.path)]
+ yield Difference.from_command(Javap, self.path, other.path)
diff --git a/diffoscope/comparators/mono.py b/diffoscope/comparators/mono.py
index cfbf87d..a9281ee 100644
--- a/diffoscope/comparators/mono.py
+++ b/diffoscope/comparators/mono.py
@@ -39,4 +39,4 @@ class MonoExeFile(File):
return MonoExeFile.RE_FILE_TYPE.search(file.magic_file_type)
def compare_details(self, other, source=None):
- return [Difference.from_command(Pedump, self.path, other.path)]
+ yield Difference.from_command(Pedump, self.path, other.path)
diff --git a/diffoscope/comparators/pdf.py b/diffoscope/comparators/pdf.py
index d105c07..d247ca8 100644
--- a/diffoscope/comparators/pdf.py
+++ b/diffoscope/comparators/pdf.py
@@ -47,7 +47,5 @@ class PdfFile(File):
return PdfFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(Pdftotext, self.path, other.path))
- differences.append(Difference.from_command(Pdftk, self.path, other.path))
- return differences
+ yield Difference.from_command(Pdftotext, self.path, other.path)
+ yield Difference.from_command(Pdftk, self.path, other.path)
diff --git a/diffoscope/comparators/png.py b/diffoscope/comparators/png.py
index 0328e33..dee6d8c 100644
--- a/diffoscope/comparators/png.py
+++ b/diffoscope/comparators/png.py
@@ -44,4 +44,4 @@ class PngFile(File):
return PngFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- return [Difference.from_command(Sng, self.path, other.path, source='sng')]
+ yield Difference.from_command(Sng, self.path, other.path, source='sng')
diff --git a/diffoscope/comparators/rpm.py b/diffoscope/comparators/rpm.py
index f6c638b..fdd9220 100644
--- a/diffoscope/comparators/rpm.py
+++ b/diffoscope/comparators/rpm.py
@@ -101,7 +101,4 @@ class RpmFile(AbstractRpmFile):
CONTAINER_CLASS = RpmContainer
def compare_details(self, other, source=None):
- differences = []
- differences.append(compare_rpm_headers(self.path, other.path))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield compare_rpm_headers(self.path, other.path)
diff --git a/diffoscope/comparators/sqlite.py b/diffoscope/comparators/sqlite.py
index e361dea..384b250 100644
--- a/diffoscope/comparators/sqlite.py
+++ b/diffoscope/comparators/sqlite.py
@@ -35,5 +35,5 @@ class Sqlite3Database(File):
return file.magic_file_type == 'SQLite 3.x database'
def compare_details(self, other, source=None):
- return [Difference.from_command(Sqlite3Dump, self.path, other.path)]
+ yield Difference.from_command(Sqlite3Dump, self.path, other.path)
diff --git a/diffoscope/comparators/squashfs.py b/diffoscope/comparators/squashfs.py
index b2b5b2f..aac05b7 100644
--- a/diffoscope/comparators/squashfs.py
+++ b/diffoscope/comparators/squashfs.py
@@ -196,8 +196,5 @@ class SquashfsFile(File):
return SquashfsFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(SquashfsSuperblock, self.path, other.path))
- differences.append(Difference.from_command(SquashfsListing, self.path, other.path))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_command(SquashfsSuperblock, self.path, other.path)
+ yield Difference.from_command(SquashfsListing, self.path, other.path)
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/tar.py
index a876bec..6080a35 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/tar.py
@@ -41,7 +41,4 @@ class TarFile(File):
return TarFile.RE_FILE_TYPE.search(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- differences.append(Difference.from_command(TarListing, self.path, other.path))
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield Difference.from_command(TarListing, self.path, other.path)
diff --git a/diffoscope/comparators/xz.py b/diffoscope/comparators/xz.py
index 98dc81d..79418f8 100644
--- a/diffoscope/comparators/xz.py
+++ b/diffoscope/comparators/xz.py
@@ -57,6 +57,3 @@ class XzFile(File):
@staticmethod
def recognizes(file):
return XzFile.RE_FILE_TYPE.match(file.magic_file_type)
-
- def compare_details(self, other, source=None):
- return self.as_container.compare(other.as_container)
diff --git a/diffoscope/comparators/zip.py b/diffoscope/comparators/zip.py
index 103cbf3..61cf4d7 100644
--- a/diffoscope/comparators/zip.py
+++ b/diffoscope/comparators/zip.py
@@ -108,10 +108,6 @@ class ZipFile(File):
return ZipFile.RE_FILE_TYPE.match(file.magic_file_type)
def compare_details(self, other, source=None):
- differences = []
- # look up differences in metadata
zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
Difference.from_command(ZipinfoVerbose, self.path, other.path)
- differences.append(zipinfo_difference)
- differences.extend(self.as_container.compare(other.as_container))
- return differences
+ yield zipinfo_difference
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index 554e29e..713e7b8 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
-from contextlib import contextmanager
+from contextlib import contextmanager, suppress
from io import StringIO
import os
import os.path
@@ -318,7 +318,7 @@ class Difference(object):
*args, **kwargs)
@staticmethod
- def from_command(cls, path1, path2, *args, **kwargs):
+ def from_command(cls, path1, path2, *args, suppress_errors=(), **kwargs):
command_args = []
if 'command_args' in kwargs:
command_args = kwargs['command_args']
@@ -338,7 +338,9 @@ class Difference(object):
if 'source' not in kwargs:
source_cmd = command1 or command2
kwargs['source'] = ' '.join(map(lambda x: '{}' if x == source_cmd.path else x, source_cmd.cmdline()))
- difference = Difference.from_feeder(feeder1, feeder2, path1, path2, *args, **kwargs)
+ difference = None
+ with suppress(*suppress_errors):
+ difference = Difference.from_feeder(feeder1, feeder2, path1, path2, *args, **kwargs)
if not difference:
return None
if command1 and command1.stderr_content:
@@ -349,6 +351,12 @@ class Difference(object):
difference.add_comment(command2.stderr_content)
return difference
+ @staticmethod
+ def from_details(path1, path2, details, source=None):
+ d = Difference(None, path1, path2, source)
+ d.add_details(details)
+ return d
+
@property
def comment(self):
return '\n'.join(self._comments)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list