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]
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
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 []