[diffoscope] 01/03: Add comparator for Postscript files
Reiner Herrmann
reiner at reiner-h.de
Sat Feb 27 19:03:16 CET 2016
This is an automated email from the git hooks/post-receive script.
deki-guest pushed a commit to branch master
in repository diffoscope.
commit d9bc6c873a4418dece906cd3f3888ea16c3811a4
Author: Reiner Herrmann <reiner at reiner-h.de>
Date: Sat Feb 27 18:24:47 2016 +0100
Add comparator for Postscript files
---
diffoscope/__init__.py | 2 ++
diffoscope/comparators/__init__.py | 2 ++
diffoscope/comparators/ps.py | 50 ++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 0eab5af..b0a9174 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -85,6 +85,8 @@ class RequiredToolNotFound(Exception):
, 'arch': 'mono-tools' }
, 'ppudump': { 'debian': 'fp-utils'
, 'arch': 'fpc' }
+ , 'ps2ascii': { 'debian': 'ghostscript'
+ , 'arch': 'ghostscript' }
, 'readelf': { 'debian': 'binutils-multiarch'
, 'arch': 'binutils' }
, 'rpm2cpio': { 'debian': 'rpm2cpio'
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 0f30351..9d710f1 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -61,6 +61,7 @@ from diffoscope.comparators.mono import MonoExeFile
from diffoscope.comparators.pdf import PdfFile
from diffoscope.comparators.png import PngFile
from diffoscope.comparators.ppu import PpuFile
+from diffoscope.comparators.ps import PsFile
try:
from diffoscope.comparators.rpm import RpmFile
except ImportError as ex:
@@ -132,6 +133,7 @@ FILE_CLASSES = (
Md5sumsFile,
DebDataTarFile,
ElfSection,
+ PsFile,
TextFile,
Bzip2File,
CpioFile,
diff --git a/diffoscope/comparators/ps.py b/diffoscope/comparators/ps.py
new file mode 100644
index 0000000..98149d9
--- /dev/null
+++ b/diffoscope/comparators/ps.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Reiner Herrmann <reiner at reiner-h.de>
+#
+# 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, RequiredToolNotFound, logger
+from diffoscope.comparators.text import TextFile
+from diffoscope.comparators.utils import Command
+from diffoscope.difference import Difference
+
+
+class Pstotext(Command):
+ @tool_required('ps2ascii')
+ def cmdline(self):
+ return ['ps2ascii', self.path]
+
+
+class PsFile(TextFile):
+ RE_FILE_TYPE = re.compile(r'^PostScript document\b')
+
+ @staticmethod
+ def recognizes(file):
+ return PsFile.RE_FILE_TYPE.match(file.magic_file_type)
+
+ def compare(self, other, source=None):
+ differences = super().compare(other, source)
+ details = None
+ try:
+ details = Difference.from_command(Pstotext, self.path, other.path)
+ except RequiredToolNotFound:
+ logger.debug('ps2ascii not found')
+
+ if details:
+ differences.add_details([details])
+ return differences
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list