[Reproducible-commits] [diffoscope] 01/01: Add diffoscope support for ppu files
Paul Mathijs Gevers
elbrus at moszumanska.debian.org
Mon Nov 2 20:05:04 UTC 2015
This is an automated email from the git hooks/post-receive script.
elbrus pushed a commit to branch master
in repository diffoscope.
commit b8395e0af4beecfd3e920b602dd94c710f07af84
Author: Paul Gevers <elbrus at debian.org>
Date: Mon Nov 2 21:03:36 2015 +0100
Add diffoscope support for ppu files
fpc unit files (ppu) are binary files that store information about fpc objects
This addition includes testcases
---
diffoscope/__init__.py | 1 +
diffoscope/comparators/__init__.py | 2 ++
diffoscope/comparators/ppu.py | 59 +++++++++++++++++++++++++++++++++
tests/comparators/test_ppu.py | 66 +++++++++++++++++++++++++++++++++++++
tests/data/ppu_expected_diff | 17 ++++++++++
tests/data/test1.ppu | Bin 0 -> 4728 bytes
tests/data/test2.ppu | Bin 0 -> 4728 bytes
7 files changed, 145 insertions(+)
diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 393f167..843d95a 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -55,6 +55,7 @@ class RequiredToolNotFound(Exception):
, 'pdftk': { 'debian': 'pdftk' }
, 'pdftotext': { 'debian': 'poppler-utils' }
, 'pedump': { 'debian': 'mono-utils' }
+ , 'ppudump': { 'debian': 'fp-utils' }
, 'readelf': { 'debian': 'binutils-multiarch' }
, 'rpm2cpio': { 'debian': 'rpm2cpio' }
, 'showttf': { 'debian': 'fontforge-extras' }
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index d7d8d2e..29292b0 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -47,6 +47,7 @@ from diffoscope.comparators.iso9660 import Iso9660File
from diffoscope.comparators.mono import MonoExeFile
from diffoscope.comparators.pdf import PdfFile
from diffoscope.comparators.png import PngFile
+from diffoscope.comparators.ppu import DotPpuFile
try:
from diffoscope.comparators.rpm import RpmFile
except ImportError as ex:
@@ -135,6 +136,7 @@ FILE_CLASSES = (
MonoExeFile,
PdfFile,
PngFile,
+ DotPpuFile,
RpmFile,
SquashfsFile,
TarFile,
diff --git a/diffoscope/comparators/ppu.py b/diffoscope/comparators/ppu.py
new file mode 100644
index 0000000..5fb8955
--- /dev/null
+++ b/diffoscope/comparators/ppu.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+# 2015 Jérémy Bobbio <lunar at debian.org>
+# 2015 Paul Gevers <elbrus 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, needs_content
+from diffoscope.comparators.utils import Command
+from diffoscope.difference import Difference
+
+
+class Ppudump(Command):
+ @tool_required('ppudump')
+ def cmdline(self):
+ return ['ppudump', self.path]
+
+ def filter(self, line):
+ if re.match(r'^Analyzing %s \(v[0-9]+\)$' % re.escape(self.path), line.decode('utf-8')):
+ return b''
+ return line
+
+
+class DotPpuFile(File):
+ RE_FILE_EXTENSION = re.compile(r'\.ppu$')
+
+ @staticmethod
+ def recognizes(file):
+ if not DotPpuFile.RE_FILE_EXTENSION.search(file.name):
+ return False
+ if file.path != None:
+ with open(file.path, 'rb') as f:
+ if re.match(rb'^PPU[0-9]+', f.read(32)):
+ return True
+ else:
+ with open(file.name, 'rb') as f:
+ if re.match(rb'^PPU[0-9]+', f.read(32)):
+ return True
+ return False
+
+ @needs_content
+ def compare_details(self, other, source=None):
+ return [Difference.from_command(Ppudump, self.path, other.path)]
diff --git a/tests/comparators/test_ppu.py b/tests/comparators/test_ppu.py
new file mode 100644
index 0000000..cdaa0bb
--- /dev/null
+++ b/tests/comparators/test_ppu.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Daniel Kahn Gillmor <dkg at fifthhorseman.net>
+# 2015 Paul Gevers <elbrus 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.ppu import DotPpuFile
+from diffoscope.config import Config
+from conftest import tool_missing
+
+# These test files were taken from two different builds of the Debian package
+# fp-units-castle-game-engine (version 5.1.1-2 on amd64) on the Debian
+# reproducible build infrastructure. The files were originally called
+# castletexturefont_dejavusans_10.ppu which are generated during package
+# building of the cge package from dejavusans font in the fonts-dejavu package.
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.ppu')
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.ppu')
+
+ at pytest.fixture
+def file1():
+ return specialize(FilesystemFile(TEST_FILE1_PATH))
+
+ at pytest.fixture
+def file2():
+ return specialize(FilesystemFile(TEST_FILE2_PATH))
+
+def test_identification(file1):
+ assert isinstance(file1, DotPpuFile)
+
+def test_no_differences(file1):
+ difference = file1.compare(file1)
+ assert difference is None
+
+ at pytest.fixture
+def differences(file1, file2):
+ return file1.compare(file2).details
+
+ at pytest.mark.skipif(tool_missing('ppudump'), reason='missing ppudump')
+def test_diff(differences):
+ print(differences[0].unified_diff)
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/ppu_expected_diff')).read()
+ assert differences[0].unified_diff == expected_diff
+
+def test_compare_non_existing(monkeypatch, file1):
+ monkeypatch.setattr(Config, 'new_file', True)
+ difference = file1.compare(NonExistingFile('/nonexisting', file1))
+ assert difference.source2 == '/nonexisting'
diff --git a/tests/data/ppu_expected_diff b/tests/data/ppu_expected_diff
new file mode 100644
index 0000000..fef9ed8
--- /dev/null
+++ b/tests/data/ppu_expected_diff
@@ -0,0 +1,17 @@
+@@ -15,15 +15,15 @@
+ Definitions stored : 200
+ Symbols stored : 21
+
+ Interface section
+ ------------------
+ Module Name: CastleTextureFont_DejaVuSans_10
+
+-Source file 1 : castletexturefont_dejavusans_10.pas 2015/11/01 13:49:43
++Source file 1 : castletexturefont_dejavusans_10.pas 2015/11/01 14:05:11
+ Uses unit: System (Crc: C28919E4, IntfcCrc: 33F67B81, IndCrc: AB715672)
+ Uses unit: objpas (Crc: 322FFBC4, IntfcCrc: 68A68DD4, IndCrc: AB715672)
+ Uses unit: CastleTextureFontData (Crc: 080D58E3, IntfcCrc: 0EE179C8, IndCrc: 70B73331)
+ Link unit object file: castletexturefont_dejavusans_10.o (static )
+ DerefMapsize: 3
+ DerefMap[0] = CASTLETEXTUREFONTDATA
+ DerefMap[1] = SYSTEM
diff --git a/tests/data/test1.ppu b/tests/data/test1.ppu
new file mode 100644
index 0000000..05d63eb
Binary files /dev/null and b/tests/data/test1.ppu differ
diff --git a/tests/data/test2.ppu b/tests/data/test2.ppu
new file mode 100644
index 0000000..8933ccf
Binary files /dev/null and b/tests/data/test2.ppu differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list