Beispiel #1
0
def compare_squashfs_files(path1, path2, source=None):
    differences = []

    # compare metadata
    difference = Difference.from_command(SquashfsSuperblock, path1, path2)
    if difference:
        differences.append(difference)
    difference = Difference.from_command(SquashfsListing, path1, path2)
    if difference:
        differences.append(difference)

    # compare files contained in archive
    files1 = get_squashfs_names(path1)
    files2 = get_squashfs_names(path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            extract_squashfs(path1, temp_dir1)
            extract_squashfs(path2, temp_dir2)
            for member in sorted(set(files1).intersection(set(files2))):
                in_path1 = os.path.join(temp_dir1, member)
                in_path2 = os.path.join(temp_dir2, member)
                if not os.path.isfile(in_path1) or not os.path.isfile(in_path2):
                    continue
                differences.extend(debbindiff.comparators.compare_files(
                    in_path1, in_path2, source=member))

    return differences
Beispiel #2
0
def compare_iso9660_files(path1, path2, source=None):
    differences = []

    # compare metadata
    difference = Difference.from_command(ISO9660PVD, path1, path2)
    if difference:
        differences.append(difference)
    for extension in (None, 'joliet', 'rockridge'):
        difference = Difference.from_command(ISO9660Listing,
                                             path1,
                                             path2,
                                             command_args=(extension, ))
        if difference:
            differences.append(difference)

    # compare files contained in image
    files1 = get_iso9660_names(path1)
    files2 = get_iso9660_names(path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            for name in sorted(set(files1).intersection(files2)):
                logger.debug('extract file %s' % name)
                in_path1 = os.path.join(temp_dir1, os.path.basename(name))
                in_path2 = os.path.join(temp_dir2, os.path.basename(name))
                with open(in_path1, 'w') as dest:
                    extract_from_iso9660(path1, name, dest)
                with open(in_path2, 'w') as dest:
                    extract_from_iso9660(path2, name, dest)
                differences.extend(
                    debbindiff.comparators.compare_files(in_path1,
                                                         in_path2,
                                                         source=name))

    return differences
Beispiel #3
0
def compare_zip_files(path1, path2, source=None):
    differences = []
    try:
        with ZipFile(path1, 'r') as zip1:
            with ZipFile(path2, 'r') as zip2:
                # look up differences in content
                with make_temp_directory() as temp_dir1:
                    with make_temp_directory() as temp_dir2:
                        for name in sorted(
                                set(zip1.namelist()).intersection(
                                    zip2.namelist())):
                            # skip directories
                            if name.endswith('/'):
                                continue
                            logger.debug('extract member %s', name)
                            in_path1 = zip1.extract(name, temp_dir1)
                            in_path2 = zip2.extract(name, temp_dir2)
                            differences.extend(
                                debbindiff.comparators.compare_files(
                                    in_path1, in_path2, source=name))
                            os.unlink(in_path1)
                            os.unlink(in_path2)
                # look up differences in metadata
                difference = Difference.from_command(Zipinfo, path1, path2)
                if not difference:
                    # search harder
                    difference = Difference.from_command(
                        ZipinfoVerbose, path1, path2)
                if difference:
                    differences.append(difference)
    except BadZipfile:
        logger.debug('Either %s or %s is not a zip file.' % (path1, path2))
        # we'll fallback on binary comparison
    return differences
Beispiel #4
0
 def with_fallback(path1, path2, source=None):
     if are_same_binaries(path1, path2):
         return []
     try:
         inside_differences = original_function(path1, path2, source)
         # no differences detected inside? let's at least do a binary diff
         if len(inside_differences) == 0:
             difference = compare_binary_files(path1, path2, source=source)[0]
             difference.comment = (difference.comment or '') + \
                 "No differences found inside, yet data differs"
         else:
             difference = Difference(None, path1, path2, source=source)
             difference.add_details(inside_differences)
     except subprocess.CalledProcessError as e:
         difference = compare_binary_files(path1, path2, source=source)[0]
         output = re.sub(r'^', '    ', e.output, flags=re.MULTILINE)
         cmd = ' '.join(e.cmd)
         difference.comment = (difference.comment or '') + \
             "Command `%s` exited with %d. Output:\n%s" \
             % (cmd, e.returncode, output)
     except RequiredToolNotFound as e:
         difference = compare_binary_files(path1, path2, source=source)[0]
         difference.comment = (difference.comment or '') + \
             "'%s' not available in path. Falling back to binary comparison." % e.command
         package = e.get_package()
         if package:
             difference.comment += "\nInstall '%s' to get a better output." % package
     return [difference]
Beispiel #5
0
def compare_iso9660_files(path1, path2, source=None):
    differences = []

    # compare metadata
    differences.append(Difference.from_command(ISO9660PVD, path1, path2))
    for extension in (None, 'joliet', 'rockridge'):
        differences.append(Difference.from_command(ISO9660Listing, path1, path2, command_args=(extension,)))

    # compare files contained in image
    files1 = get_iso9660_names(path1)
    files2 = get_iso9660_names(path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            for name in sorted(set(files1).intersection(files2)):
                logger.debug('extract file %s' % name)
                in_path1 = os.path.join(temp_dir1, os.path.basename(name))
                in_path2 = os.path.join(temp_dir2, os.path.basename(name))
                with open(in_path1, 'w') as dest:
                    extract_from_iso9660(path1, name, dest)
                with open(in_path2, 'w') as dest:
                    extract_from_iso9660(path2, name, dest)
                differences.append(debbindiff.comparators.compare_files(
                    in_path1, in_path2, source=name))

    return differences
Beispiel #6
0
def compare_directories(path1, path2, source=None):
    differences = []
    logger.debug('path1 files: %s' % sorted(set(os.listdir(path1))))
    logger.debug('path2 files: %s' % sorted(set(os.listdir(path2))))
    for name in sorted(set(os.listdir(path1)).intersection(set(os.listdir(path2)))):
        logger.debug('compare %s' % name)
        in_path1 = os.path.join(path1, name)
        in_path2 = os.path.join(path2, name)
        in_difference = debbindiff.comparators.compare_files(
                            in_path1, in_path2, source=name)
        if not os.path.isdir(in_path1):
            if in_difference:
                in_difference.add_details(compare_meta(in_path1, in_path2))
            else:
                details = compare_meta(in_path1, in_path2)
                if details:
                    d = Difference(None, path1, path2, source=name)
                    d.add_details(details)
                    in_difference = d
        differences.append(in_difference)
    ls1 = ls(path1)
    ls2 = ls(path2)
    differences.append(Difference.from_unicode(ls1, ls2, path1, path2, source="ls"))
    differences.extend(compare_meta(path1, path2))
    return differences
Beispiel #7
0
 def wrap_details(path1, path2, source=None):
     details = [d for d in original_function(path1, path2, source) if d is not None]
     if len(details) == 0:
         return None
     difference = Difference(None, path1, path2, source=source)
     difference.add_details(details)
     return difference
Beispiel #8
0
def compare_zip_files(path1, path2, source=None):
    differences = []
    try:
        with ZipFile(path1, 'r') as zip1:
            with ZipFile(path2, 'r') as zip2:
                # look up differences in content
                with make_temp_directory() as temp_dir1:
                    with make_temp_directory() as temp_dir2:
                        for name in sorted(set(zip1.namelist())
                                           .intersection(zip2.namelist())):
                            # skip directories
                            if name.endswith('/'):
                                continue
                            logger.debug('extract member %s', name)
                            in_path1 = zip1.extract(name, temp_dir1)
                            in_path2 = zip2.extract(name, temp_dir2)
                            differences.append(
                                debbindiff.comparators.compare_files(
                                    in_path1, in_path2,
                                    source=name))
                            os.unlink(in_path1)
                            os.unlink(in_path2)
                # look up differences in metadata
                difference = Difference.from_command(Zipinfo, path1, path2)
                if not difference:
                    # search harder
                    difference = Difference.from_command(ZipinfoVerbose, path1, path2)
                differences.append(difference)
    except BadZipfile:
        logger.debug('Either %s or %s is not a zip file.' % (path1, path2))
        # we'll fallback on binary comparison
    return differences
Beispiel #9
0
def compare_meta(path1, path2):
    logger.debug('compare_meta(%s, %s)' % (path1, path2))
    differences = []

    try:
        difference = Difference.from_command(Stat, path1, path2)
        if difference:
            differences.append(difference)
    except RequiredToolNotFound:
        logger.warn("'stat' not found! Is PATH wrong?")

    try:
        lsattr1 = lsattr(path1)
        lsattr2 = lsattr(path2)
        difference = Difference.from_unicode(
                         lsattr1, lsattr2, path1, path2, source="lattr")
        if difference:
            differences.append(difference)
    except RequiredToolNotFound:
        logger.info("Unable to find 'lsattr'.")

    try:
        difference = Difference.from_command(Getfacl, path1, path2)
        if difference:
            differences.append(difference)
    except RequiredToolNotFound:
        logger.info("Unable to find 'getfacl'.")
    return differences
Beispiel #10
0
def compare_pdf_files(path1, path2, source=None):
    differences = []
    difference = Difference.from_command(Pdftotext, path1, path2)
    if difference:
        differences.append(difference)
    difference = Difference.from_command(Pdftk, path1, path2)
    if difference:
        differences.append(difference)
    return differences
Beispiel #11
0
def compare_binary_files(path1, path2, source=None):
    try:
        with xxd(path1) as xxd1:
            with xxd(path2) as xxd2:
                return Difference.from_file(xxd1, xxd2, path1, path2, source)
    except RequiredToolNotFound:
        hexdump1 = hexdump_fallback(path1)
        hexdump2 = hexdump_fallback(path2)
        comment = 'xxd not available in path. Falling back to Python hexlify.\n'
        return Difference.from_unicode(hexdump1, hexdump2, path1, path2, source, comment)
Beispiel #12
0
def compare_directories(path1, path2, source=None):
    differences = []
    logger.debug('path1 files: %s' % sorted(set(os.listdir(path1))))
    logger.debug('path2 files: %s' % sorted(set(os.listdir(path2))))
    for name in sorted(set(os.listdir(path1)).intersection(set(os.listdir(path2)))):
        logger.debug('compare %s' % name)
        in_path1 = os.path.join(path1, name)
        in_path2 = os.path.join(path2, name)
        in_differences = debbindiff.comparators.compare_files(
                             in_path1, in_path2, source=name)
        if not os.path.isdir(in_path1):
            if in_differences:
                in_differences[0].add_details(compare_meta(in_path1, in_path2))
            else:
                d = Difference(None, path1, path2, source=name)
                d.add_details(compare_meta(in_path1, in_path2))
                in_differences = [d]
        differences.extend(in_differences)
    ls1 = ls(path1)
    ls2 = ls(path2)
    difference = Difference.from_unicode(ls1, ls2, path1, path2, source="ls")
    if difference:
        differences.append(difference)
    differences.extend(compare_meta(path1, path2))
    if differences:
        d = Difference(None, path1, path2, source=source)
        d.add_details(differences)
        return [d]
    return []
Beispiel #13
0
def _compare_elf_data(path1, path2, source=None):
    differences = []
    difference = Difference.from_command(ReadelfAll, path1, path2)
    if difference:
        differences.append(difference)
    difference = Difference.from_command(ReadelfDebugDump, path1, path2)
    if difference:
        differences.append(difference)
    difference = Difference.from_command(ObjdumpDisassemble, path1, path2)
    if difference:
        differences.append(difference)
    return differences
Beispiel #14
0
def compare_binary_files(path1, path2, source=None):
    try:
        with xxd(path1) as xxd1:
            with xxd(path2) as xxd2:
                difference = Difference.from_file(xxd1, xxd2, path1, path2,
                                                  source)
    except RequiredToolNotFound:
        hexdump1 = hexdump_fallback(path1)
        hexdump2 = hexdump_fallback(path2)
        comment = 'xxd not available in path. Falling back to Python hexlify.\n'
        difference = Difference.from_unicode(hexdump1, hexdump2, path1, path2,
                                             source, comment)
    if not difference:
        return []
    return [difference]
Beispiel #15
0
def compare_deb_files(path1, path2, source=None):
    differences = []
    # look up differences in content
    ar1 = ArFile(filename=path1)
    ar2 = ArFile(filename=path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            logger.debug('content1 %s', ar1.getnames())
            logger.debug('content2 %s', ar2.getnames())
            for name in sorted(set(ar1.getnames())
                               .intersection(ar2.getnames())):
                logger.debug('extract member %s', name)
                member1 = ar1.getmember(name)
                member2 = ar2.getmember(name)
                in_path1 = os.path.join(temp_dir1, name)
                in_path2 = os.path.join(temp_dir2, name)
                with open(in_path1, 'w') as f1:
                    f1.write(member1.read())
                with open(in_path2, 'w') as f2:
                    f2.write(member2.read())
                differences.extend(
                    debbindiff.comparators.compare_files(
                        in_path1, in_path2, source=name))
                os.unlink(in_path1)
                os.unlink(in_path2)
    # look up differences in file list and file metadata
    content1 = get_ar_content(path1)
    content2 = get_ar_content(path2)
    difference = Difference.from_unicode(
                     content1, content2, path1, path2, source="metadata")
    if difference:
        differences.append(difference)
    return differences
Beispiel #16
0
def compare_cpio_files(path1, path2, source=None):
    differences = []

    difference = Difference.from_command(CpioContent,
                                         path1,
                                         path2,
                                         source="file list")
    if difference:
        differences.append(difference)

    # compare files contained in archive
    content1 = get_cpio_names(path1)
    content2 = get_cpio_names(path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            extract_cpio_archive(path1, temp_dir1)
            extract_cpio_archive(path2, temp_dir2)
            files1 = content1.splitlines(1)
            files2 = content2.splitlines(1)
            for member in sorted(set(files1).intersection(set(files2))):
                in_path1 = os.path.join(temp_dir1, member)
                in_path2 = os.path.join(temp_dir2, member)
                if not os.path.isfile(in_path1) or not os.path.isfile(
                        in_path2):
                    continue
                differences.extend(
                    debbindiff.comparators.compare_files(in_path1,
                                                         in_path2,
                                                         source=member))

    return differences
Beispiel #17
0
def compare_rpm_files(path1, path2, source=None):
    try:
        import rpm
    except ImportError:
        logger.info("Python module rpm not found.")
        return []

    differences = []

    # compare headers
    with make_temp_directory() as rpmdb_dir:
        rpm.addMacro("_dbpath", rpmdb_dir)
        ts = rpm.TransactionSet()
        ts.setVSFlags(-1)
        header1 = get_rpm_header(path1, ts)
        header2 = get_rpm_header(path2, ts)
        difference = Difference.from_unicode(
                         header1, header2, path1, path2, source="header")
        if difference:
            differences.append(difference)

    # extract cpio archive
    with extract_rpm_payload(path1) as archive1:
        with extract_rpm_payload(path2) as archive2:
            differences.extend(debbindiff.comparators.compare_files(
                archive1, archive2, source=get_source(archive1, archive2)))

    return differences
Beispiel #18
0
def compare_tar_files(path1, path2, source=None):
    differences = []
    with tarfile.open(path1, 'r') as tar1:
        with tarfile.open(path2, 'r') as tar2:
            # look up differences in content
            with make_temp_directory() as temp_dir1:
                with make_temp_directory() as temp_dir2:
                    logger.debug('content1 %s', tar1.getnames())
                    logger.debug('content2 %s', tar2.getnames())
                    for name in sorted(set(tar1.getnames())
                                       .intersection(tar2.getnames())):
                        member1 = tar1.getmember(name)
                        member2 = tar2.getmember(name)
                        if not member1.isfile() or not member2.isfile():
                            continue
                        logger.debug('extract member %s', name)
                        tar1.extract(name, temp_dir1)
                        tar2.extract(name, temp_dir2)
                        in_path1 = os.path.join(temp_dir1, name).decode('utf-8')
                        in_path2 = os.path.join(temp_dir2, name).decode('utf-8')
                        differences.append(
                            debbindiff.comparators.compare_files(
                                in_path1, in_path2,
                                source=name.decode('utf-8')))
                        os.unlink(in_path1)
                        os.unlink(in_path2)
            # look up differences in file list and file metadata
            content1 = get_tar_content(tar1).decode('utf-8')
            content2 = get_tar_content(tar2).decode('utf-8')
            differences.append(Difference.from_unicode(
                                   content1, content2, path1, path2, source="metadata"))
    return differences
Beispiel #19
0
def compare_cpio_files(path1, path2, source=None):
    differences = []

    difference = Difference.from_command(
                     CpioContent, path1, path2, source="file list")
    if difference:
        differences.append(difference)

    # compare files contained in archive
    content1 = get_cpio_names(path1)
    content2 = get_cpio_names(path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            extract_cpio_archive(path1, temp_dir1)
            extract_cpio_archive(path2, temp_dir2)
            files1 = content1.splitlines(1)
            files2 = content2.splitlines(1)
            for member in sorted(set(files1).intersection(set(files2))):
                in_path1 = os.path.join(temp_dir1, member)
                in_path2 = os.path.join(temp_dir2, member)
                if not os.path.isfile(in_path1) or not os.path.isfile(in_path2):
                    continue
                differences.extend(debbindiff.comparators.compare_files(
                    in_path1, in_path2, source=member))

    return differences
Beispiel #20
0
def compare_rpm_files(path1, path2, source=None):
    try:
        import rpm
    except ImportError:
        logger.info("Python module rpm not found.")
        return []

    differences = []

    # compare headers
    with make_temp_directory() as rpmdb_dir:
        rpm.addMacro("_dbpath", rpmdb_dir)
        ts = rpm.TransactionSet()
        ts.setVSFlags(-1)
        header1 = get_rpm_header(path1, ts)
        header2 = get_rpm_header(path2, ts)
        difference = Difference.from_unicode(header1,
                                             header2,
                                             path1,
                                             path2,
                                             source="header")
        if difference:
            differences.append(difference)

    # extract cpio archive
    with extract_rpm_payload(path1) as archive1:
        with extract_rpm_payload(path2) as archive2:
            differences.extend(
                debbindiff.comparators.compare_files(archive1,
                                                     archive2,
                                                     source=get_source(
                                                         archive1, archive2)))

    return differences
Beispiel #21
0
def compare_text_files(path1, path2, encoding=None, source=None):
    if encoding is None:
        encoding = 'utf-8'
    try:
        file1 = codecs.open(path1, 'r', encoding=encoding)
        file2 = codecs.open(path2, 'r', encoding=encoding)
        return Difference.from_file(file1, file2, path1, path2, source)
    except (LookupError, UnicodeDecodeError):
        # unknown or misdetected encoding
        return compare_binary_files(path1, path2, source)
Beispiel #22
0
def compare_md5sums_files(path1, path2, source=None):
    if are_same_binaries(path1, path2):
        return []
    return [
        Difference(None,
                   path1,
                   path2,
                   source=get_source(path1, path2),
                   comment="Files in package differs")
    ]
Beispiel #23
0
def compare_static_lib_files(path1, path2, source=None):
    differences = []
    # look up differences in metadata
    content1 = get_ar_content(path1)
    content2 = get_ar_content(path2)
    difference = Difference.from_unicode(
                     content1, content2, path1, path2, source="metadata")
    if difference:
        differences.append(difference)
    differences.extend(_compare_elf_data(path1, path2, source))
    return differences
Beispiel #24
0
 def with_fallback(path1, path2, source=None):
     if are_same_binaries(path1, path2):
         return []
     try:
         inside_differences = original_function(path1, path2, source)
         # no differences detected inside? let's at least do a binary diff
         if len(inside_differences) == 0:
             difference = compare_binary_files(path1, path2,
                                               source=source)[0]
             difference.comment = (difference.comment or '') + \
                 "No differences found inside, yet data differs"
         else:
             difference = Difference(None, path1, path2, source=source)
             difference.add_details(inside_differences)
     except subprocess.CalledProcessError as e:
         difference = compare_binary_files(path1, path2, source=source)[0]
         output = re.sub(r'^', '    ', e.output, flags=re.MULTILINE)
         cmd = ' '.join(e.cmd)
         difference.comment = (difference.comment or '') + \
             "Command `%s` exited with %d. Output:\n%s" \
             % (cmd, e.returncode, output)
     except RequiredToolNotFound as e:
         difference = compare_binary_files(path1, path2, source=source)[0]
         difference.comment = (difference.comment or '') + \
             "'%s' not available in path. Falling back to binary comparison." % e.command
         package = e.get_package()
         if package:
             difference.comment += "\nInstall '%s' to get a better output." % package
     return [difference]
Beispiel #25
0
def compare_gzip_files(path1, path2, source=None):
    differences = []
    # check metadata
    metadata1 = get_gzip_metadata(path1)
    metadata2 = get_gzip_metadata(path2)
    differences.append(Difference.from_unicode(
                           metadata1, metadata2, path1, path2, source='metadata'))
    # check content
    with decompress_gzip(path1) as new_path1:
        with decompress_gzip(path2) as new_path2:
            differences.append(debbindiff.comparators.compare_files(
                new_path1, new_path2,
                source=[os.path.basename(new_path1), os.path.basename(new_path2)]))
    return differences
Beispiel #26
0
def compare_ipk_files(path1, path2, source=None):
    differences = []

    # metadata
    metadata1 = get_gzip_metadata(path1)
    metadata2 = get_gzip_metadata(path2)
    differences.append(Difference.from_unicode(
                           metadata1, metadata2, path1, path2, source='metadata'))

    # content
    with decompress_gzip(path1) as tar1:
        with decompress_gzip(path2) as tar2:
            differences.append(compare_tar_files(tar1, tar2,
                    source=[os.path.basename(tar1), os.path.basename(tar2)]))

    return differences
Beispiel #27
0
def compare_files(path1, path2, source=None):
    if os.path.islink(path1) or os.path.islink(path2):
        dest1, dest2 = None, None
        try:
            dest1 = os.readlink(path1)
            text1 = "%s -> %s" % (path1, dest1)
        except OSError:
            text1 = "[ No symlink ]"

        try:
            dest2 = os.readlink(path2)
            text2 = "%s -> %s" % (path2, dest2)
        except OSError:
            text2 = "[ No symlink ]"

        if dest1 and dest2 and dest1 == dest2:
            return None
        return Difference.from_unicode(text1, text2, path1, path2, source=source, comment="symlink")

    if os.path.isdir(path1) and os.path.isdir(path2):
        return compare_directories(path1, path2, source)
    if not os.path.isfile(path1):
        logger.critical("%s is not a file", path1)
        sys.exit(2)
    if not os.path.isfile(path2):
        logger.critical("%s is not a file", path2)
        sys.exit(2)
    # try comparing small files directly first
    size1 = os.path.getsize(path1)
    size2 = os.path.getsize(path2)
    if size1 == size2 and size1 <= SMALL_FILE_THRESHOLD:
        if file(path1).read() == file(path2).read():
            return None
    # ok, let's do the full thing
    mime_type1 = guess_mime_type(path1)
    mime_type2 = guess_mime_type(path2)
    for mime_type_regex, filename_regex, comparator in COMPARATORS:
        if filename_regex and re.search(filename_regex, path1) \
           and re.search(filename_regex, path2):
            return comparator(path1, path2, source=source)
        if mime_type_regex:
            match1 = re.search(mime_type_regex, mime_type1)
            match2 = re.search(mime_type_regex, mime_type2)
            if match1 and match2 and match1.groupdict() == match2.groupdict():
                return comparator(path1, path2, source=source, **match1.groupdict())
    return compare_unknown(path1, path2, source)
Beispiel #28
0
def compare_rpm_files(path1, path2, source=None):
    differences = []

    # compare headers
    with make_temp_directory() as rpmdb_dir:
        rpm.addMacro("_dbpath", rpmdb_dir)
        ts = rpm.TransactionSet()
        ts.setVSFlags(-1)
        header1 = get_rpm_header(path1, ts)
        header2 = get_rpm_header(path2, ts)
        differences.append(Difference.from_unicode(header1, header2, path1, path2, source="header"))

    # extract cpio archive
    with extract_rpm_payload(path1) as archive1:
        with extract_rpm_payload(path2) as archive2:
            differences.append(
                debbindiff.comparators.compare_files(archive1, archive2, source=get_source(archive1, archive2))
            )

    return differences
Beispiel #29
0
def compare_tar_files(path1, path2, source=None):
    differences = []
    with tarfile.open(path1, 'r') as tar1:
        with tarfile.open(path2, 'r') as tar2:
            # look up differences in content
            with make_temp_directory() as temp_dir1:
                with make_temp_directory() as temp_dir2:
                    logger.debug('content1 %s', tar1.getnames())
                    logger.debug('content2 %s', tar2.getnames())
                    for name in sorted(
                            set(tar1.getnames()).intersection(
                                tar2.getnames())):
                        member1 = tar1.getmember(name)
                        member2 = tar2.getmember(name)
                        if not member1.isfile() or not member2.isfile():
                            continue
                        logger.debug('extract member %s', name)
                        tar1.extract(name, temp_dir1)
                        tar2.extract(name, temp_dir2)
                        in_path1 = os.path.join(temp_dir1, name)
                        in_path2 = os.path.join(temp_dir2, name)
                        differences.extend(
                            debbindiff.comparators.compare_files(in_path1,
                                                                 in_path2,
                                                                 source=name))
                        os.unlink(in_path1)
                        os.unlink(in_path2)
            # look up differences in file list and file metadata
            content1 = get_tar_content(tar1).decode('utf-8')
            content2 = get_tar_content(tar2).decode('utf-8')
            difference = Difference.from_unicode(content1,
                                                 content2,
                                                 path1,
                                                 path2,
                                                 source="metadata")
            if difference:
                differences.append(difference)
    return differences
Beispiel #30
0
def compare_deb_files(path1, path2, source=None):
    differences = []
    # look up differences in content
    ar1 = ArFile(filename=path1)
    ar2 = ArFile(filename=path2)
    with make_temp_directory() as temp_dir1:
        with make_temp_directory() as temp_dir2:
            logger.debug('content1 %s', ar1.getnames())
            logger.debug('content2 %s', ar2.getnames())
            for name in sorted(
                    set(ar1.getnames()).intersection(ar2.getnames())):
                logger.debug('extract member %s', name)
                member1 = ar1.getmember(name)
                member2 = ar2.getmember(name)
                in_path1 = os.path.join(temp_dir1, name)
                in_path2 = os.path.join(temp_dir2, name)
                with open(in_path1, 'w') as f1:
                    f1.write(member1.read())
                with open(in_path2, 'w') as f2:
                    f2.write(member2.read())
                differences.extend(
                    debbindiff.comparators.compare_files(in_path1,
                                                         in_path2,
                                                         source=name))
                os.unlink(in_path1)
                os.unlink(in_path2)
    # look up differences in file list and file metadata
    content1 = get_ar_content(path1)
    content2 = get_ar_content(path2)
    difference = Difference.from_unicode(content1,
                                         content2,
                                         path1,
                                         path2,
                                         source="metadata")
    if difference:
        differences.append(difference)
    return differences
Beispiel #31
0
def compare_gzip_files(path1, path2, source=None):
    differences = []
    # check metadata
    metadata1 = get_gzip_metadata(path1)
    metadata2 = get_gzip_metadata(path2)
    difference = Difference.from_unicode(metadata1,
                                         metadata2,
                                         path1,
                                         path2,
                                         source='metadata')
    if difference:
        differences.append(difference)
    # check content
    with decompress_gzip(path1) as new_path1:
        with decompress_gzip(path2) as new_path2:
            differences.extend(
                debbindiff.comparators.compare_files(
                    new_path1,
                    new_path2,
                    source=[
                        os.path.basename(new_path1),
                        os.path.basename(new_path2)
                    ]))
    return differences
Beispiel #32
0
def compare_hi_files(path1, path2, source=None):
    return [Difference.from_command(ShowIface, path1, path2)]
Beispiel #33
0
        dot_changes1 = Changes(filename=path1)
        dot_changes1.validate(check_signature=False)
        dot_changes2 = Changes(filename=path2)
        dot_changes2.validate(check_signature=False)
    except IOError, e:
        logger.critical(e)
        sys.exit(2)

    differences = []
    for field in DOT_CHANGES_FIELDS:
        if dot_changes1[field] != dot_changes2[field]:
            content1 = "%s: %s" % (field, dot_changes1[field])
            content2 = "%s: %s" % (field, dot_changes2[field])
            difference = Difference.from_unicode(
                             content1, content2,
                             dot_changes1.get_changes_file(),
                             dot_changes2.get_changes_file(),
                             source=source)
            if difference:
                differences.append(difference)

    # This will handle differences in the list of files, checksums, priority
    # and section
    files1 = dot_changes1.get('Files')
    files2 = dot_changes2.get('Files')
    logger.debug(dot_changes1.get_as_string('Files'))

    files_difference = Difference.from_unicode(
        dot_changes1.get_as_string('Files'),
        dot_changes2.get_as_string('Files'),
        dot_changes1.get_changes_file(),
Beispiel #34
0
def compare_png_files(path1, path2, source=None):
    difference = Difference.from_command(Sng, path1, path2, source='sng')
    if not difference:
        return []
    return [difference]
Beispiel #35
0
def compare_mo_files(path1, path2, source=None):
    return [Difference.from_command(Msgunfmt, path1, path2)]
Beispiel #36
0
def compare_ttf_files(path1, path2, source=None):
    return [Difference.from_command(Showttf, path1, path2)]
Beispiel #37
0
def compare_ttf_files(path1, path2, source=None):
    difference = Difference.from_command(Showttf, path1, path2)
    if not difference:
        return []
    return [difference]
Beispiel #38
0
def compare_mo_files(path1, path2, source=None):
    difference = Difference.from_command(Msgunfmt, path1, path2)
    if not difference:
        return []
    return [difference]
Beispiel #39
0
@binary_fallback
@returns_details
def compare_dot_changes_files(path1, path2, source=None):
    try:
        dot_changes1 = Changes(filename=path1)
        dot_changes1.validate(check_signature=False)
        dot_changes2 = Changes(filename=path2)
        dot_changes2.validate(check_signature=False)
    except IOError, e:
        logger.critical(e)
        sys.exit(2)

    differences = []
    for field in DOT_CHANGES_FIELDS:
        differences.append(Difference.from_unicode(
                               dot_changes1[field].lstrip(),
                               dot_changes2[field].lstrip(),
                               path1, path2, source=field))

    files_difference = Difference.from_unicode(
        dot_changes1.get_as_string('Files'),
        dot_changes2.get_as_string('Files'),
        path1, path2,
        source='Files')

    if not files_difference:
        return differences

    differences.append(files_difference)

    # we are only interested in file names
    files1 = dict([(d['name'], d) for d in dot_changes1.get('Files')])
Beispiel #40
0
def compare_class_files(path1, path2, source=None):
    return [Difference.from_command(Javap, path1, path2)]
Beispiel #41
0
def compare_png_files(path1, path2, source=None):
    return [Difference.from_command(Sng, path1, path2, source='sng')]
Beispiel #42
0
def compare_mo_files(path1, path2, source=None):
    difference = Difference.from_command(Msgunfmt, path1, path2)
    if not difference:
        return []
    return [difference]