Skip to content
Snippets Groups Projects
Commit f311a6df authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Support comparing .ico files using img2txt (Closes: #850730)


Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent a7495215
No related branches found
No related tags found
No related merge requests found
......@@ -65,6 +65,7 @@ COMPARATORS = (
('zip.ZipFile',),
('zip.MozillaZipFile',),
('image.JPEGImageFile',),
('image.ICOImageFile',),
('cbfs.CbfsFile',),
('git.GitIndexFile',),
('openssh.PublicKeyFile',),
......
......@@ -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
......@@ -127,6 +127,9 @@ class RequiredToolNotFound(Exception):
'arch': 'gettext',
'FreeBSD': 'gettext-tools',
},
'icotool': {
'debian': 'icoutils',
},
'nm': {
'debian': 'binutils-multiarch',
'arch': 'binutils',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment