[diffoscope] 02/02: specialize: Tidy and add better logging.
Chris Lamb
chris at chris-lamb.co.uk
Sun Jan 15 13:01: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 4ef72d4c652e687926ef800f937220caaf835267
Author: Chris Lamb <lamby at debian.org>
Date: Sun Jan 15 22:58:23 2017 +1100
specialize: Tidy and add better logging.
Signed-off-by: Chris Lamb <lamby at debian.org>
---
diffoscope/comparators/utils/specialize.py | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index 49f1811..a30818d 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -31,22 +31,31 @@ def specialize(file):
for cls in FILE_CLASSES:
if isinstance(file, cls):
return file
- ret = False
+
+ # Does this file class match?
+ flag = False
if hasattr(cls, 'recognizes'):
with profile('recognizes', file):
- ret = cls.recognizes(file)
+ flag = 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)
+ flag = bool(cls.RE_FILE_TYPE.search(file.magic_file_type))
elif hasattr(cls, 'RE_FILE_EXTENSION'):
- ret = cls.RE_FILE_EXTENSION.search(file.name)
- if ret:
- logger.debug("Using %s for %s", cls.__name__, file.name)
- new_cls = type(cls.__name__, (cls, type(file)), {})
- file.__class__ = new_cls
- return file
- logger.debug('Unidentified file. Magic says: %s', file.magic_file_type)
+ flag = bool(cls.RE_FILE_EXTENSION.search(file.name))
+
+ if not flag:
+ continue
+
+ # Found a match; perform type magic
+ logger.debug("Using %s for %s", cls.__name__, file.name)
+ new_cls = type(cls.__name__, (cls, type(file)), {})
+ file.__class__ = new_cls
+
+ return file
+
+ logger.debug("Unidentified file. Magic says: %s", file.magic_file_type)
+
return file
def import_comparators(comparators):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list