[diffoscope] 02/02: Support comparing .ico files using img2txt (Closes: #850730)

Chris Lamb chris at chris-lamb.co.uk
Tue Jan 10 22:56:46 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 f311a6df28230be7d7afe0aadfd371471c392ccf
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Jan 10 21:56:40 2017 +0000

    Support comparing .ico files using img2txt (Closes: #850730)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/__init__.py |  1 +
 diffoscope/comparators/image.py    | 24 ++++++++++++++++++++++++
 diffoscope/exc.py                  |  3 +++
 3 files changed, 28 insertions(+)

diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 3807630..29a5749 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -65,6 +65,7 @@ COMPARATORS = (
     ('zip.ZipFile',),
     ('zip.MozillaZipFile',),
     ('image.JPEGImageFile',),
+    ('image.ICOImageFile',),
     ('cbfs.CbfsFile',),
     ('git.GitIndexFile',),
     ('openssh.PublicKeyFile',),
diff --git a/diffoscope/comparators/image.py b/diffoscope/comparators/image.py
index 91091ec..d47e21b 100644
--- a/diffoscope/comparators/image.py
+++ b/diffoscope/comparators/image.py
@@ -18,8 +18,10 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import re
+import subprocess
 
 from diffoscope.tools import tool_required
+from diffoscope.tempfiles import get_named_temporary_file
 from diffoscope.difference import Difference
 
 from .utils.file import File
@@ -51,3 +53,25 @@ class JPEGImageFile(File):
 
     def compare_details(self, other, source=None):
         return [Difference.from_command(Img2Txt, self.path, other.path)]
+
+class ICOImageFile(File):
+    RE_FILE_TYPE = re.compile(r'\bMS Windows icon resource\b')
+
+    @staticmethod
+    def recognizes(file):
+        return ICOImageFile.RE_FILE_TYPE.search(file.magic_file_type)
+
+    def compare_details(self, other, source=None):
+        # img2txt does not support .ico files directly so convert to .PNG.
+        xs = [ICOImageFile.convert(x) for x in (self, other)]
+
+        return [Difference.from_command(Img2Txt, *xs)]
+
+    @staticmethod
+    @tool_required('icotool')
+    def convert(file):
+        result = get_named_temporary_file().name
+
+        subprocess.check_call(('icotool', '-x', '-o', result, file.path))
+
+        return result
diff --git a/diffoscope/exc.py b/diffoscope/exc.py
index 82b8e84..0724a6b 100644
--- a/diffoscope/exc.py
+++ b/diffoscope/exc.py
@@ -127,6 +127,9 @@ class RequiredToolNotFound(Exception):
             'arch': 'gettext',
             'FreeBSD': 'gettext-tools',
         },
+        'icotool': {
+            'debian': 'icoutils',
+        },
         'nm': {
             'debian': 'binutils-multiarch',
             'arch': 'binutils',

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


More information about the diffoscope mailing list