[diffoscope] 01/01: Add support for ICC profiles

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Feb 15 23:05:37 CET 2016


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

lunar pushed a commit to branch master
in repository diffoscope.

commit 65f0512fe991fc99467f652942e715216033ae90
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Mon Feb 15 22:47:29 2016 +0100

    Add support for ICC profiles
---
 diffoscope/__init__.py             |   1 +
 diffoscope/comparators/__init__.py |   2 ++
 diffoscope/comparators/icc.py      |  41 +++++++++++++++++++++++++
 tests/comparators/test_icc.py      |  61 +++++++++++++++++++++++++++++++++++++
 tests/data/icc_expected_diff       |  23 ++++++++++++++
 tests/data/test1.icc               | Bin 0 -> 14684 bytes
 tests/data/test2.icc               | Bin 0 -> 14684 bytes
 7 files changed, 128 insertions(+)

diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 133e481..5b530db 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -42,6 +42,7 @@ class RequiredToolNotFound(Exception):
     PROVIDERS = { 'bzip2':      { 'debian': 'bzip2',
                                   'arch': 'bzip2'}
                 , 'cbfstool':   {}
+                , 'cd-iccdump': { 'debian': 'colord' }
                 , 'cmp':        { 'debian': 'diffutils',
                                   'arch': 'diffutils'}
                 , 'cpio':       { 'debian': 'cpio',
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 5224ca1..0f30351 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -52,6 +52,7 @@ from diffoscope.comparators.fonts import TtfFile
 from diffoscope.comparators.gettext import MoFile
 from diffoscope.comparators.gzip import GzipFile
 from diffoscope.comparators.haskell import HiFile
+from diffoscope.comparators.icc import IccFile
 from diffoscope.comparators.image import ImageFile
 from diffoscope.comparators.ipk import IpkFile
 from diffoscope.comparators.iso9660 import Iso9660File
@@ -146,6 +147,7 @@ FILE_CLASSES = (
     IpkFile,
     GzipFile,
     HiFile,
+    IccFile,
     Iso9660File,
     ClassFile,
     MonoExeFile,
diff --git a/diffoscope/comparators/icc.py b/diffoscope/comparators/icc.py
new file mode 100644
index 0000000..37648b5
--- /dev/null
+++ b/diffoscope/comparators/icc.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Jérémy Bobbio <lunar at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
+
+import re
+from diffoscope import tool_required
+from diffoscope.comparators.binary import File
+from diffoscope.comparators.utils import Command
+from diffoscope.difference import Difference
+
+
+class Iccdump(Command):
+    @tool_required('cd-iccdump')
+    def cmdline(self):
+          return ['cd-iccdump', self.path]
+
+
+class IccFile(File):
+    RE_FILE_EXTENSION = re.compile(r'\bICC Profile$')
+
+    @staticmethod
+    def recognizes(file):
+        return IccFile.RE_FILE_EXTENSION.search(file.magic_file_type)
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(Iccdump, self.path, other.path)]
diff --git a/tests/comparators/test_icc.py b/tests/comparators/test_icc.py
new file mode 100644
index 0000000..b08bc3e
--- /dev/null
+++ b/tests/comparators/test_icc.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Jérémy Bobbio <lunar at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+import pytest
+from diffoscope.comparators import specialize
+from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.icc import IccFile
+from diffoscope.config import Config
+from conftest import tool_missing
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.icc')
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.icc')
+
+ at pytest.fixture
+def icc1():
+    return specialize(FilesystemFile(TEST_FILE1_PATH))
+
+ at pytest.fixture
+def icc2():
+    return specialize(FilesystemFile(TEST_FILE2_PATH))
+
+def test_identification(icc1):
+    assert isinstance(icc1, IccFile)
+
+def test_no_differences(icc1):
+    difference = icc1.compare(icc1)
+    assert difference is None
+
+ at pytest.fixture
+def differences(icc1, icc2):
+    return icc1.compare(icc2).details
+
+ at pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
+def test_diff(differences):
+    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/icc_expected_diff')).read()
+    assert differences[0].unified_diff == expected_diff
+
+ at pytest.mark.skipif(tool_missing('cd-iccdump'), reason='missing cd-iccdump')
+def test_compare_non_existing(monkeypatch, icc1):
+    monkeypatch.setattr(Config, 'new_file', True)
+    difference = icc1.compare(NonExistingFile('/nonexisting', icc1))
+    assert difference.source2 == '/nonexisting'
+    assert len(difference.details) > 0
+
diff --git a/tests/data/icc_expected_diff b/tests/data/icc_expected_diff
new file mode 100644
index 0000000..63efebf
--- /dev/null
+++ b/tests/data/icc_expected_diff
@@ -0,0 +1,23 @@
+@@ -1,20 +1,20 @@
+ icc:
+ Header:
+   Size		= 14684 bytes
+   Version	= 4.3
+   Profile Kind	= display-device
+   Colorspace	= rgb
+   Conn. Space	= xyz
+-  Date, Time	= 2016-02-15, 21:02:09
++  Date, Time	= 2016-02-15, 21:03:22
+   Flags		= Not embedded profile, Use anywhere
+   Dev. Attrbts	= reflective, glossy
+   Rndrng Intnt	= perceptual
+   Creator	= lcms
+-  Profile ID	= 0x0477fa4b
++  Profile ID	= 0x06017f17
+ 
+ tag 00:
+   sig	'desc' [0x64657363]
+   size	38
+   type	'mluc' [0x6d6c7563]
+ Text:
+   en_US:	sRGB [24 bytes]
diff --git a/tests/data/test1.icc b/tests/data/test1.icc
new file mode 100644
index 0000000..1c97458
Binary files /dev/null and b/tests/data/test1.icc differ
diff --git a/tests/data/test2.icc b/tests/data/test2.icc
new file mode 100644
index 0000000..45eb433
Binary files /dev/null and b/tests/data/test2.icc differ

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


More information about the diffoscope mailing list