Commit d647eb75 authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Add support for comparing the "text" content of HTML files using html2text....

Add support for comparing the "text" content of HTML files using html2text. (Closes: #318, Debian:#1022209)
parent 06fd0c79
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ Build-Depends:
 gnupg-utils <!nocheck>,
 hdf5-tools <!nocheck>,
 help2man,
 html2text <!nocheck>,
 imagemagick <!nocheck>,
 jsbeautifier <!nocheck>,
 libarchive-tools <!nocheck>,
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
#   $ mv debian/tests/control.tmp debian/tests/control

Tests: pytest-with-recommends
Depends: python3-all, diffoscope, black, python3-pytest, python3-h5py, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apksigner, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, coreboot-utils, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, ffmpeg, fontforge-extras, fonttools, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnumeric, gnupg, gnupg-utils, hdf5-tools, imagemagick, jsbeautifier, libarchive-tools, libxmlb-dev, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, oggvideotools [!s390x], openssh-client, openssl, pgpdump, poppler-utils, procyon-decompiler, python3-pdfminer, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, u-boot-tools, unzip, wabt, xmlbeans, xxd, xz-utils, zip, zstd, androguard, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Depends: python3-all, diffoscope, black, python3-pytest, python3-h5py, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apksigner, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, coreboot-utils, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, ffmpeg, fontforge-extras, fonttools, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnumeric, gnupg, gnupg-utils, hdf5-tools, html2text, imagemagick, jsbeautifier, libarchive-tools, libxmlb-dev, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, oggvideotools [!s390x], openssh-client, openssl, pgpdump, poppler-utils, procyon-decompiler, python3-pdfminer, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, u-boot-tools, unzip, wabt, xmlbeans, xxd, xz-utils, zip, zstd, 

Tests: pytest
Depends: python3-all, diffoscope, python3-pytest, python3-h5py, file, python3-tlsh
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class ComparatorManager:
        ("xmlb.XMLBFile",),
        ("openssl.Pkcs7File",),
        ("openssl.MobileProvisionFile",),
        ("html.HtmlFile",),
        ("text.TextFile",),
        ("bzip2.Bzip2File",),
        ("cpio.CpioFile",),
+50 −0
Original line number Diff line number Diff line
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2022 Chris Lamb <lamby@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 <https://www.gnu.org/licenses/>.

import re

from diffoscope.difference import Difference
from diffoscope.exc import RequiredToolNotFound
from diffoscope.tools import tool_required

from .text import TextFile
from .utils.command import Command


class Htmltotext(Command):
    @tool_required("html2text")
    def cmdline(self):
        return ["html2text", self.path]


class HtmlFile(TextFile):
    DESCRIPTION = "HTML files (.html)"
    FILE_TYPE_RE = re.compile(r"^HTML document")

    def compare(self, other, source=None):
        difference = super().compare(other, source)

        # Show text-only differences as a sub-diff.
        try:
            text = Difference.from_operation(Htmltotext, self.path, other.path)
            if text is not None:
                difference.add_details([text])
        except RequiredToolNotFound as exc:  # noqa
            difference.add_comment(exc.get_comment())

        return difference
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ EXTERNAL_TOOLS = {
    },
    "gzip": {"debian": "gzip", "arch": "gzip", "guix": "gzip"},
    "h5dump": {"debian": "hdf5-tools", "arch": "hdf5", "guix": "hdf5"},
    "html2text": {"debian": "html2text"},
    "identify": {
        "debian": "imagemagick",
        "arch": "imagemagick",
Loading