Loading diffoscope/comparators/directory.py +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import subprocess from diffoscope.exc import RequiredToolNotFound from diffoscope.tools import tool_required from diffoscope.progress import Progress from diffoscope.excludes import filter_excludes from diffoscope.difference import Difference from .binary import FilesystemFile Loading Loading @@ -167,6 +168,7 @@ class FilesystemDirectory(object): my_names = my_container.get_member_names() other_names = other_container.get_member_names() to_compare = set(my_names).intersection(other_names) to_compare = set(filter_excludes(to_compare)) with Progress(len(to_compare)) as p: for name in sorted(to_compare): my_file = my_container.get_member(name) Loading diffoscope/comparators/utils/compare.py +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import binascii from diffoscope.tools import tool_required from diffoscope.exc import RequiredToolNotFound from diffoscope.config import Config from diffoscope.excludes import any_excluded from diffoscope.profiling import profile from diffoscope.difference import Difference Loading @@ -52,6 +53,8 @@ def compare_root_paths(path1, path2): if not Config().new_file: bail_if_non_existing(path1, path2) if any_excluded(path1, path2): return None if os.path.isdir(path1) and os.path.isdir(path2): return compare_directories(path1, path2) container1 = FilesystemDirectory(os.path.dirname(path1)).as_container Loading @@ -69,6 +72,9 @@ def compare_files(file1, file2, source=None): file2.__class__.__name__, ) if any_excluded(file1.name, file2.name): return None with profile('has_same_content_as', file1): if file1.has_same_content_as(file2): logger.debug("has_same_content_as returned True; skipping further comparisons") Loading diffoscope/comparators/utils/libarchive.py +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import logging import libarchive import collections from diffoscope.excludes import any_excluded from diffoscope.tempfiles import get_temporary_directory from ..device import Device Loading Loading @@ -212,6 +213,10 @@ class LibarchiveContainer(Archive): if entry.isdir: continue # Save extracting excluded files if any_excluded(entry.pathname): continue # Maintain a mapping of archive path to the extracted path, # avoiding the need to sanitise filenames. dst = os.path.join(tmpdir, '{}'.format(idx)) Loading diffoscope/config.py +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ class Config(object): new_file = False fuzzy_threshold = 60 enforce_constraints = True excludes = () _singleton = {} Loading diffoscope/excludes.py 0 → 100644 +42 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- # # diffoscope: in-depth comparison of files, archives, and directories # # Copyright © 2017 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 fnmatch import logging from diffoscope.config import Config logger = logging.getLogger(__name__) def filter_excludes(filenames): result = [] for x in filenames: for y in Config().excludes: if fnmatch.fnmatchcase(x, y): logger.debug("Excluding %s as it matches pattern '%s'", x, y) break else: result.append(x) return result def any_excluded(*filenames): return len(filter_excludes(filenames)) != len(filenames) Loading
diffoscope/comparators/directory.py +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import subprocess from diffoscope.exc import RequiredToolNotFound from diffoscope.tools import tool_required from diffoscope.progress import Progress from diffoscope.excludes import filter_excludes from diffoscope.difference import Difference from .binary import FilesystemFile Loading Loading @@ -167,6 +168,7 @@ class FilesystemDirectory(object): my_names = my_container.get_member_names() other_names = other_container.get_member_names() to_compare = set(my_names).intersection(other_names) to_compare = set(filter_excludes(to_compare)) with Progress(len(to_compare)) as p: for name in sorted(to_compare): my_file = my_container.get_member(name) Loading
diffoscope/comparators/utils/compare.py +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import binascii from diffoscope.tools import tool_required from diffoscope.exc import RequiredToolNotFound from diffoscope.config import Config from diffoscope.excludes import any_excluded from diffoscope.profiling import profile from diffoscope.difference import Difference Loading @@ -52,6 +53,8 @@ def compare_root_paths(path1, path2): if not Config().new_file: bail_if_non_existing(path1, path2) if any_excluded(path1, path2): return None if os.path.isdir(path1) and os.path.isdir(path2): return compare_directories(path1, path2) container1 = FilesystemDirectory(os.path.dirname(path1)).as_container Loading @@ -69,6 +72,9 @@ def compare_files(file1, file2, source=None): file2.__class__.__name__, ) if any_excluded(file1.name, file2.name): return None with profile('has_same_content_as', file1): if file1.has_same_content_as(file2): logger.debug("has_same_content_as returned True; skipping further comparisons") Loading
diffoscope/comparators/utils/libarchive.py +5 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import logging import libarchive import collections from diffoscope.excludes import any_excluded from diffoscope.tempfiles import get_temporary_directory from ..device import Device Loading Loading @@ -212,6 +213,10 @@ class LibarchiveContainer(Archive): if entry.isdir: continue # Save extracting excluded files if any_excluded(entry.pathname): continue # Maintain a mapping of archive path to the extracted path, # avoiding the need to sanitise filenames. dst = os.path.join(tmpdir, '{}'.format(idx)) Loading
diffoscope/config.py +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ class Config(object): new_file = False fuzzy_threshold = 60 enforce_constraints = True excludes = () _singleton = {} Loading
diffoscope/excludes.py 0 → 100644 +42 −0 Original line number Diff line number Diff line # -*- coding: utf-8 -*- # # diffoscope: in-depth comparison of files, archives, and directories # # Copyright © 2017 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 fnmatch import logging from diffoscope.config import Config logger = logging.getLogger(__name__) def filter_excludes(filenames): result = [] for x in filenames: for y in Config().excludes: if fnmatch.fnmatchcase(x, y): logger.debug("Excluding %s as it matches pattern '%s'", x, y) break else: result.append(x) return result def any_excluded(*filenames): return len(filter_excludes(filenames)) != len(filenames)