How to use the diffoscope.difference.Difference.from_command function in diffoscope

To help you get started, we’ve selected a few diffoscope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github anthraxx / diffoscope / tests / comparators / test_utils.py View on Github external
def test_trim_stderr_in_command():
    class FillStderr(Command):
        def cmdline(self):
            return ['tee', '/dev/stderr']

        def feed_stdin(self, stdin):
            for dummy in range(0, Command.MAX_STDERR_LINES + 1):
                stdin.write('error {}\n'.format(self.path).encode('utf-8'))
    difference = Difference.from_command(FillStderr, 'dummy1', 'dummy2')
    assert '[ 1 lines ignored ]' in difference.comment
github anthraxx / diffoscope / diffoscope / comparators / iso9660.py View on Github external
def compare_details(self, other, source=None):
        differences = []
        differences.append(Difference.from_command(ISO9660PVD, self.path, other.path))
        differences.append(Difference.from_command(ISO9660Listing, self.path, other.path))
        for extension in ('joliet', 'rockridge'):
            try:
                differences.append(Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,)))
            except subprocess.CalledProcessError:
                pass # probably no joliet or rockridge data
        return differences
github anthraxx / diffoscope / diffoscope / comparators / macho.py View on Github external
def compare_details(self, other, source=None):
        differences = []
        # Check for fat binaries, trigger a difference if the architectures differ
        my_archs = MachoFile.get_arch_from_macho(self.path)
        other_archs = MachoFile.get_arch_from_macho(other.path)

        differences.append(Difference.from_text('\n'.join(my_archs),
                                                '\n'.join(other_archs),
                                                self.name, other.name, source='architectures'))

        # Compare common architectures for differences
        for common_arch in set(my_archs) & set(other_archs):
            differences.append(Difference.from_command(OtoolHeaders, self.path, other.path, command_args=[common_arch],
                                                       comment="Mach-O headers for architecture %s" % common_arch))
            differences.append(Difference.from_command(OtoolLibraries, self.path, other.path, command_args=[common_arch],
                                                       comment="Mach-O load commands for architecture %s" % common_arch))
            differences.append(Difference.from_command(OtoolDisassemble, self.path, other.path, command_args=[common_arch],
                                                       comment="Code for architecture %s" % common_arch))

        return differences
github anthraxx / diffoscope / diffoscope / comparators / elf.py View on Github external
def _compare_elf_data(path1, path2):
    return [
        Difference.from_command(x, path1, path2)
        for x in list(READELF_COMMANDS) + READELF_DEBUG_DUMP_COMMANDS
    ]
github anthraxx / diffoscope / diffoscope / comparators / javascript.py View on Github external
def compare_details(self, other, source=None):
        return [Difference.from_command(JavaScriptBeautify, self.path, other.path)]
github anthraxx / diffoscope / diffoscope / comparators / ar.py View on Github external
def compare_details(self, other, source=None):
        return [Difference.from_command(ArSymbolTableDumper, self.path, other.path),
                Difference.from_text_readers(list_libarchive(self.path),
                                             list_libarchive(other.path),
                                             self.path, other.path, source="file list")]
github anthraxx / diffoscope / diffoscope / comparators / elf.py View on Github external
def compare(self, other, source=None):
        return Difference.from_command(
            ObjdumpDisassembleSection,
            self.path,
            other.path,
            command_args=[self._name],
        )
github anthraxx / diffoscope / diffoscope / comparators / directory.py View on Github external
def compare_meta(path1, path2):
    logger.debug('compare_meta(%s, %s)', path1, path2)
    differences = []
    try:
        differences.append(Difference.from_command(Stat, path1, path2))
    except RequiredToolNotFound:
        logger.warning("'stat' not found! Is PATH wrong?")
    if os.path.islink(path1) or os.path.islink(path2):
        return [d for d in differences if d is not None]
    try:
        lsattr1 = lsattr(path1)
        lsattr2 = lsattr(path2)
        differences.append(Difference.from_text(
                               lsattr1, lsattr2, path1, path2, source="lsattr"))
    except RequiredToolNotFound:
        logger.info("Unable to find 'lsattr'.")
    try:
        differences.append(Difference.from_command(Getfacl, path1, path2))
    except RequiredToolNotFound:
        logger.info("Unable to find 'getfacl'.")
    return [d for d in differences if d is not None]
github anthraxx / diffoscope / diffoscope / comparators / ps.py View on Github external
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:  # noqa
            logger.debug('ps2ascii not found')

        if details:
            differences.add_details([details])
        return differences
github anthraxx / diffoscope / diffoscope / comparators / directory.py View on Github external
differences = []
    try:
        differences.append(Difference.from_command(Stat, path1, path2))
    except RequiredToolNotFound:
        logger.warning("'stat' not found! Is PATH wrong?")
    if os.path.islink(path1) or os.path.islink(path2):
        return [d for d in differences if d is not None]
    try:
        lsattr1 = lsattr(path1)
        lsattr2 = lsattr(path2)
        differences.append(Difference.from_text(
                               lsattr1, lsattr2, path1, path2, source="lsattr"))
    except RequiredToolNotFound:
        logger.info("Unable to find 'lsattr'.")
    try:
        differences.append(Difference.from_command(Getfacl, path1, path2))
    except RequiredToolNotFound:
        logger.info("Unable to find 'getfacl'.")
    return [d for d in differences if d is not None]