[Reproducible-commits] [debbindiff] 02/02: Add support for PDF files
Jérémy Bobbio
lunar at moszumanska.debian.org
Thu Jan 8 11:00:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit b3fbe5658789e01fa6ee034c65900c90b3e65356
Author: Jérémy Bobbio <lunar at debian.org>
Date: Thu Jan 8 12:00:03 2015 +0100
Add support for PDF files
---
README | 36 ++++++++++++------------
debbindiff/comparators/__init__.py | 2 ++
debbindiff/comparators/pdf.py | 56 ++++++++++++++++++++++++++++++++++++++
debian/control | 2 ++
4 files changed, 79 insertions(+), 17 deletions(-)
diff --git a/README b/README
index 1b4b115..ff6bd98 100644
--- a/README
+++ b/README
@@ -26,23 +26,25 @@ External dependencies
The various comparators rely on these external commands being available
in the path:
-| command | Debian package |
-+----------|--------------------|
-| ar | binutils-multiarch |
-| bzip2 | bzip2 |
-| file | file |
-| ghc | ghc |
-| gpg | gnupg |
-| gzip | gzip |
-| msgunfmt | gettext |
-| objdump | binutils-multiarch |
-| readelf | binutils-multiarch |
-| showttf | fontforge-extras |
-| sng | sng |
-| vim | vim |
-| xxd | vim-common |
-| xz | xz-utils |
-| zipinfo | unzip |
+| command | Debian package |
++-----------|--------------------|
+| ar | binutils-multiarch |
+| bzip2 | bzip2 |
+| file | file |
+| ghc | ghc |
+| gpg | gnupg |
+| gzip | gzip |
+| msgunfmt | gettext |
+| objdump | binutils-multiarch |
+| pdftk | pdftk |
+| pdftotext | poppler-utils |
+| readelf | binutils-multiarch |
+| showttf | fontforge-extras |
+| sng | sng |
+| vim | vim |
+| xxd | vim-common |
+| xz | xz-utils |
+| zipinfo | unzip |
Authors
-------
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index 4997a7d..bf22bbb 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -32,6 +32,7 @@ from debbindiff.comparators.fonts import compare_ttf_files
from debbindiff.comparators.gettext import compare_mo_files
from debbindiff.comparators.gzip import compare_gzip_files
from debbindiff.comparators.haskell import compare_hi_files
+from debbindiff.comparators.pdf import compare_pdf_files
from debbindiff.comparators.png import compare_png_files
from debbindiff.comparators.text import compare_text_files
from debbindiff.comparators.tar import compare_tar_files
@@ -78,6 +79,7 @@ COMPARATORS = [
compare_elf_files),
(r'^application/(x-font-ttf|vnd.ms-opentype)(;|$)', r'\.(ttf|otf)$', compare_ttf_files),
(r'^image/png(;|$)', r'\.png$', compare_png_files),
+ (r'^application/pdf(;|$)', r'\.pdf$', compare_pdf_files),
(None, r'\.a$', compare_static_lib_files),
]
diff --git a/debbindiff/comparators/pdf.py b/debbindiff/comparators/pdf.py
new file mode 100644
index 0000000..38a1d4c
--- /dev/null
+++ b/debbindiff/comparators/pdf.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# debdindiff 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.
+#
+# debbindiff 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 debbindiff. If not, see <http://www.gnu.org/licenses/>.
+
+import subprocess
+from debbindiff.comparators.utils import binary_fallback
+from debbindiff.difference import Difference, get_source
+
+
+def uncompress(path):
+ output = subprocess.check_output(
+ ['pdftk', path, 'output', '-', 'uncompress'],
+ shell=False, close_fds=True)
+ return output.decode('latin-1').encode('ascii', 'backslashreplace')
+
+
+def pdftotext(path):
+ return subprocess.check_output(
+ ['pdftotext', path, '-'],
+ shell=False, close_fds=True)
+
+
+ at binary_fallback
+def compare_pdf_files(path1, path2, source=None):
+ differences = []
+ src = get_source(path1, path2) or 'FILE'
+ text1 = pdftotext(path1)
+ text2 = pdftotext(path2)
+ if text1 != text2:
+ differences.append(
+ Difference(text1.splitlines(1), text2.splitlines(1),
+ text1, text2,
+ source="pdftotext %s" % src))
+ uncompressed1 = uncompress(path1)
+ uncompressed2 = uncompress(path2)
+ if uncompressed1 != uncompressed2:
+ differences.append(
+ Difference(uncompressed1.splitlines(1), uncompressed2.splitlines(1),
+ path1, path2,
+ source="pdftk %s output - uncompress" % src))
+ return differences
diff --git a/debian/control b/debian/control
index deb0074..4eb0979 100644
--- a/debian/control
+++ b/debian/control
@@ -24,6 +24,8 @@ Depends: binutils-multiarch,
gettext,
ghc,
gnupg,
+ pdftk,
+ poppler-utils,
sng,
unzip,
vim,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list