[diffoscope] 01/03: Implement auto recognition for RE_FILE_TYPE if no recognizes() method exists

Mattia Rizzolo mattia at debian.org
Sat Jan 14 11:01:58 UTC 2017


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

mattia pushed a commit to branch wip/auto-recognize
in repository diffoscope.

commit a85d1553949e65cd818c95f1ff97d25e378088ed
Author: Mattia Rizzolo <mattia at debian.org>
Date:   Sat Jan 14 11:13:55 2017 +0100

    Implement auto recognition for RE_FILE_TYPE if no recognizes() method exists
---
 diffoscope/comparators/utils/specialize.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index dd22e0b..0a18eb2 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -32,7 +32,14 @@ def specialize(file):
         if isinstance(file, cls):
             return file
         with profile('recognizes', file):
-            if cls.recognizes(file):
+            ret = False
+            if hasattr(cls, 'recognizes'):
+                ret = cls.recognizes(file)
+            else:
+                # No recognizes() method specified, try an auto recognition
+                if hasattr(cls, 'RE_FILE_TYPE'):
+                    ret = cls.RE_FILE_TYPE.search(file.magic_file_type)
+            if ret:
                 logger.debug("Using %s for %s", cls.__name__, file.name)
                 new_cls = type(cls.__name__, (cls, type(file)), {})
                 file.__class__ = new_cls

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