[diffoscope] 01/01: Make use of the new auto recognize to remove a bunch of recognizes() methods dealing with simple RE_FILE_TYPE matching

Chris Lamb chris at chris-lamb.co.uk
Sun Jan 15 13:06:11 CET 2017


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

lamby pushed a commit to branch master
in repository diffoscope.

commit 840e1c8d4a5bc441f59fe425d7e4d65d13638218
Author: Mattia Rizzolo <mattia at debian.org>
Date:   Sat Jan 14 11:36:37 2017 +0100

    Make use of the new auto recognize to remove a bunch of recognizes() methods dealing with simple RE_FILE_TYPE matching
---
 diffoscope/comparators/ar.py           | 4 ----
 diffoscope/comparators/bzip2.py        | 4 ----
 diffoscope/comparators/cpio.py         | 4 ----
 diffoscope/comparators/deb.py          | 4 ----
 diffoscope/comparators/dex.py          | 4 ----
 diffoscope/comparators/elf.py          | 4 ----
 diffoscope/comparators/fonts.py        | 4 ----
 diffoscope/comparators/fsimage.py      | 4 ----
 diffoscope/comparators/gettext.py      | 4 ----
 diffoscope/comparators/git.py          | 4 ----
 diffoscope/comparators/gzip.py         | 4 ----
 diffoscope/comparators/icc.py          | 4 ----
 diffoscope/comparators/iso9660.py      | 4 ----
 diffoscope/comparators/java.py         | 4 ----
 diffoscope/comparators/macho.py        | 4 ----
 diffoscope/comparators/mono.py         | 4 ----
 diffoscope/comparators/openssh.py      | 4 ----
 diffoscope/comparators/pdf.py          | 4 ----
 diffoscope/comparators/png.py          | 4 ----
 diffoscope/comparators/ps.py           | 4 ----
 diffoscope/comparators/rpm_fallback.py | 4 ----
 diffoscope/comparators/squashfs.py     | 4 ----
 diffoscope/comparators/tar.py          | 4 ----
 diffoscope/comparators/text.py         | 4 ----
 diffoscope/comparators/xz.py           | 4 ----
 diffoscope/comparators/zip.py          | 4 ----
 26 files changed, 104 deletions(-)

diff --git a/diffoscope/comparators/ar.py b/diffoscope/comparators/ar.py
index a8634ee..361f741 100644
--- a/diffoscope/comparators/ar.py
+++ b/diffoscope/comparators/ar.py
@@ -59,10 +59,6 @@ class ArFile(File):
     CONTAINER_CLASS = ArContainer
     RE_FILE_TYPE = re.compile(r'\bar archive\b')
 
-    @staticmethod
-    def recognizes(file):
-        return ArFile.RE_FILE_TYPE.search(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_command(ArSymbolTableDumper, self.path, other.path),
                 Difference.from_text_readers(list_libarchive(self.path),
diff --git a/diffoscope/comparators/bzip2.py b/diffoscope/comparators/bzip2.py
index aac1999..e54b28b 100644
--- a/diffoscope/comparators/bzip2.py
+++ b/diffoscope/comparators/bzip2.py
@@ -59,7 +59,3 @@ class Bzip2Container(Archive):
 class Bzip2File(File):
     CONTAINER_CLASS = Bzip2Container
     RE_FILE_TYPE = re.compile(r'^bzip2 compressed data\b')
-
-    @staticmethod
-    def recognizes(file):
-        return Bzip2File.RE_FILE_TYPE.match(file.magic_file_type)
diff --git a/diffoscope/comparators/cpio.py b/diffoscope/comparators/cpio.py
index db52afd..551360d 100644
--- a/diffoscope/comparators/cpio.py
+++ b/diffoscope/comparators/cpio.py
@@ -38,10 +38,6 @@ class CpioFile(File):
     CONTAINER_CLASS = LibarchiveContainer
     RE_FILE_TYPE = re.compile(r'\bcpio archive\b')
 
-    @staticmethod
-    def recognizes(file):
-        return CpioFile.RE_FILE_TYPE.search(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_text_readers(list_libarchive(self.path),
                                              list_libarchive(other.path),
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 95fb992..3415d83 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -82,10 +82,6 @@ class DebFile(File):
     CONTAINER_CLASS = DebContainer
     RE_FILE_TYPE = re.compile(r'^Debian binary package')
 
-    @staticmethod
-    def recognizes(file):
-        return DebFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     @property
     def md5sums(self):
         if not hasattr(self, '_md5sums'):
diff --git a/diffoscope/comparators/dex.py b/diffoscope/comparators/dex.py
index 37b53c7..3232c06 100644
--- a/diffoscope/comparators/dex.py
+++ b/diffoscope/comparators/dex.py
@@ -60,7 +60,3 @@ class DexContainer(Archive):
 class DexFile(File):
     RE_FILE_TYPE = re.compile(r'^Dalvik dex file .*\b')
     CONTAINER_CLASS = DexContainer
-
-    @staticmethod
-    def recognizes(file):
-        return DexFile.RE_FILE_TYPE.match(file.magic_file_type)
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index ca2e9ea..276fdfa 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -532,10 +532,6 @@ class ElfFile(File):
     CONTAINER_CLASS = ElfContainer
     RE_FILE_TYPE = re.compile(r'^ELF ')
 
-    @staticmethod
-    def recognizes(file):
-        return ElfFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return _compare_elf_data(self.path, other.path)
 
diff --git a/diffoscope/comparators/fonts.py b/diffoscope/comparators/fonts.py
index e5fbea0..1584d07 100644
--- a/diffoscope/comparators/fonts.py
+++ b/diffoscope/comparators/fonts.py
@@ -38,9 +38,5 @@ class Showttf(Command):
 class TtfFile(File):
     RE_FILE_TYPE = re.compile(r'^(TrueType|OpenType) font data$')
 
-    @staticmethod
-    def recognizes(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)]
diff --git a/diffoscope/comparators/fsimage.py b/diffoscope/comparators/fsimage.py
index ed324b0..f30bbb7 100644
--- a/diffoscope/comparators/fsimage.py
+++ b/diffoscope/comparators/fsimage.py
@@ -76,10 +76,6 @@ class FsImageFile(File):
     CONTAINER_CLASS = FsImageContainer
     RE_FILE_TYPE = re.compile(r'^(Linux.*filesystem data|BTRFS Filesystem).*')
 
-    @staticmethod
-    def recognizes(file):
-        return FsImageFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         differences = []
         my_fs = ''
diff --git a/diffoscope/comparators/gettext.py b/diffoscope/comparators/gettext.py
index 37b8556..5801e91 100644
--- a/diffoscope/comparators/gettext.py
+++ b/diffoscope/comparators/gettext.py
@@ -63,9 +63,5 @@ class Msgunfmt(Command):
 class MoFile(File):
     RE_FILE_TYPE = re.compile(r'^GNU message catalog\b')
 
-    @staticmethod
-    def recognizes(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)]
diff --git a/diffoscope/comparators/git.py b/diffoscope/comparators/git.py
index 0f49889..6d1b40f 100644
--- a/diffoscope/comparators/git.py
+++ b/diffoscope/comparators/git.py
@@ -30,10 +30,6 @@ from .utils.file import File
 class GitIndexFile(File):
     RE_FILE_TYPE = re.compile(r'^Git index')
 
-    @staticmethod
-    def recognizes(file):
-        return GitIndexFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_text(
             describe_index(self.path),
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index f3a1d1a..565c3b4 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -60,9 +60,5 @@ class GzipFile(object):
     CONTAINER_CLASS = GzipContainer
     RE_FILE_TYPE = re.compile(r'^gzip compressed data\b')
 
-    @staticmethod
-    def recognizes(file):
-        return GzipFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
diff --git a/diffoscope/comparators/icc.py b/diffoscope/comparators/icc.py
index 2ee24aa..8f5d141 100644
--- a/diffoscope/comparators/icc.py
+++ b/diffoscope/comparators/icc.py
@@ -35,9 +35,5 @@ class Iccdump(Command):
 class IccFile(File):
     RE_FILE_TYPE = re.compile(r'\bColorSync (ICC|color) [Pp]rofile')
 
-    @staticmethod
-    def recognizes(file):
-        return IccFile.RE_FILE_TYPE.search(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_command(Iccdump, self.path, other.path)]
diff --git a/diffoscope/comparators/iso9660.py b/diffoscope/comparators/iso9660.py
index bc47540..389549a 100644
--- a/diffoscope/comparators/iso9660.py
+++ b/diffoscope/comparators/iso9660.py
@@ -67,10 +67,6 @@ class Iso9660File(File):
     CONTAINER_CLASS = LibarchiveContainer
     RE_FILE_TYPE = re.compile(r'\bISO 9660\b')
 
-    @staticmethod
-    def recognizes(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))
diff --git a/diffoscope/comparators/java.py b/diffoscope/comparators/java.py
index b91bd25..4b3e724 100644
--- a/diffoscope/comparators/java.py
+++ b/diffoscope/comparators/java.py
@@ -46,9 +46,5 @@ class Javap(Command):
 class ClassFile(File):
     RE_FILE_TYPE = re.compile(r'^compiled Java class data\b')
 
-    @staticmethod
-    def recognizes(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)]
diff --git a/diffoscope/comparators/macho.py b/diffoscope/comparators/macho.py
index ee38d76..a4225cd 100644
--- a/diffoscope/comparators/macho.py
+++ b/diffoscope/comparators/macho.py
@@ -71,10 +71,6 @@ class MachoFile(File):
     RE_EXTRACT_ARCHS = re.compile(r'^(?:Architectures in the fat file: .* are|Non-fat file: .* is architecture): (.*)$')
 
     @staticmethod
-    def recognizes(file):
-        return MachoFile.RE_FILE_TYPE.match(file.magic_file_type)
-
-    @staticmethod
     @tool_required('lipo')
     def get_arch_from_macho(path):
         lipo_output = subprocess.check_output(['lipo', '-info', path]).decode('utf-8')
diff --git a/diffoscope/comparators/mono.py b/diffoscope/comparators/mono.py
index 2a04a25..08f2646 100644
--- a/diffoscope/comparators/mono.py
+++ b/diffoscope/comparators/mono.py
@@ -36,9 +36,5 @@ class Pedump(Command):
 class MonoExeFile(File):
     RE_FILE_TYPE = re.compile(r'\bPE[0-9]+\b.*\bMono\b')
 
-    @staticmethod
-    def recognizes(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)]
diff --git a/diffoscope/comparators/openssh.py b/diffoscope/comparators/openssh.py
index 9133088..f17c44a 100644
--- a/diffoscope/comparators/openssh.py
+++ b/diffoscope/comparators/openssh.py
@@ -34,10 +34,6 @@ class SSHKeyList(Command):
 class PublicKeyFile(File):
     RE_FILE_TYPE = re.compile(r'^OpenSSH \S+ public key')
 
-    @staticmethod
-    def recognizes(file):
-        return PublicKeyFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_command(SSHKeyList, self.path, other.path)]
 
diff --git a/diffoscope/comparators/pdf.py b/diffoscope/comparators/pdf.py
index ea114dc..6221cf4 100644
--- a/diffoscope/comparators/pdf.py
+++ b/diffoscope/comparators/pdf.py
@@ -44,10 +44,6 @@ class Pdftk(Command):
 class PdfFile(File):
     RE_FILE_TYPE = re.compile(r'^PDF document\b')
 
-    @staticmethod
-    def recognizes(file):
-        return PdfFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_command(Pdftotext, self.path, other.path),
                 Difference.from_command(Pdftk, self.path, other.path)]
diff --git a/diffoscope/comparators/png.py b/diffoscope/comparators/png.py
index 3d0918c..f3b3fdb 100644
--- a/diffoscope/comparators/png.py
+++ b/diffoscope/comparators/png.py
@@ -41,9 +41,5 @@ class Sng(Command):
 class PngFile(File):
     RE_FILE_TYPE = re.compile(r'^PNG image data\b')
 
-    @staticmethod
-    def recognizes(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')]
diff --git a/diffoscope/comparators/ps.py b/diffoscope/comparators/ps.py
index ec9506e..5be2c20 100644
--- a/diffoscope/comparators/ps.py
+++ b/diffoscope/comparators/ps.py
@@ -39,10 +39,6 @@ class Pstotext(Command):
 class PsFile(TextFile):
     RE_FILE_TYPE = re.compile(r'^PostScript document\b')
 
-    @staticmethod
-    def recognizes(file):
-        return PsFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare(self, other, source=None):
         differences = super().compare(other, source)
         details = None
diff --git a/diffoscope/comparators/rpm_fallback.py b/diffoscope/comparators/rpm_fallback.py
index 15fd31b..dfc7187 100644
--- a/diffoscope/comparators/rpm_fallback.py
+++ b/diffoscope/comparators/rpm_fallback.py
@@ -25,10 +25,6 @@ from .utils.file import File
 class AbstractRpmFile(File):
     RE_FILE_TYPE = re.compile('^RPM\s')
 
-    @staticmethod
-    def recognizes(file):
-        return AbstractRpmFile.RE_FILE_TYPE.search(file.magic_file_type)
-
 class RpmFile(AbstractRpmFile):
     def compare(self, other, source=None):
         difference = self.compare_bytes(other)
diff --git a/diffoscope/comparators/squashfs.py b/diffoscope/comparators/squashfs.py
index df88bc1..7d7cf0e 100644
--- a/diffoscope/comparators/squashfs.py
+++ b/diffoscope/comparators/squashfs.py
@@ -244,10 +244,6 @@ class SquashfsFile(File):
     CONTAINER_CLASS = SquashfsContainer
     RE_FILE_TYPE = re.compile(r'^Squashfs filesystem\b')
 
-    @staticmethod
-    def recognizes(file):
-        return SquashfsFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_command(SquashfsSuperblock, self.path, other.path),
                 Difference.from_command(SquashfsListing, self.path, other.path)]
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/tar.py
index 49dfcb0..6e0331b 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/tar.py
@@ -32,10 +32,6 @@ class TarFile(File):
     CONTAINER_CLASS = TarContainer
     RE_FILE_TYPE = re.compile(r'\btar archive\b')
 
-    @staticmethod
-    def recognizes(file):
-        return TarFile.RE_FILE_TYPE.search(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         return [Difference.from_text_readers(list_libarchive(self.path),
                                         list_libarchive(other.path),
diff --git a/diffoscope/comparators/text.py b/diffoscope/comparators/text.py
index fc2f446..3f968f9 100644
--- a/diffoscope/comparators/text.py
+++ b/diffoscope/comparators/text.py
@@ -38,10 +38,6 @@ def order_only_difference(unified_diff):
 class TextFile(File):
     RE_FILE_TYPE = re.compile(r'\btext\b')
 
-    @staticmethod
-    def recognizes(file):
-        return TextFile.RE_FILE_TYPE.search(file.magic_file_type)
-
     @property
     def encoding(self):
         if not hasattr(self, '_encoding'):
diff --git a/diffoscope/comparators/xz.py b/diffoscope/comparators/xz.py
index ff7c703..d75853a 100644
--- a/diffoscope/comparators/xz.py
+++ b/diffoscope/comparators/xz.py
@@ -59,7 +59,3 @@ class XzContainer(Archive):
 class XzFile(File):
     CONTAINER_CLASS = XzContainer
     RE_FILE_TYPE = re.compile(r'^XZ compressed data$')
-
-    @staticmethod
-    def recognizes(file):
-        return XzFile.RE_FILE_TYPE.match(file.magic_file_type)
diff --git a/diffoscope/comparators/zip.py b/diffoscope/comparators/zip.py
index 46f1881..f7dccbd 100644
--- a/diffoscope/comparators/zip.py
+++ b/diffoscope/comparators/zip.py
@@ -106,10 +106,6 @@ class ZipFile(File):
     CONTAINER_CLASS = ZipContainer
     RE_FILE_TYPE = re.compile(r'^(Zip archive|Java archive|EPUB document|OpenDocument (Text|Spreadsheet|Presentation|Drawing|Formula|Template|Text Template))\b')
 
-    @staticmethod
-    def recognizes(file):
-        return ZipFile.RE_FILE_TYPE.match(file.magic_file_type)
-
     def compare_details(self, other, source=None):
         zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
                              Difference.from_command(ZipinfoVerbose, self.path, other.path)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list