Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Exclusion Filters #705

Merged
merged 23 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement exclude list dialog on the Qt side
  • Loading branch information
glubsy committed Aug 17, 2020
commit 2eaf7e7893be7e09cba17a65c6ef80eaa741398a
4 changes: 2 additions & 2 deletions core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .util import cmp_value, fix_surrogate_encoding
from . import directories, results, export, fs, prioritize
from .ignore import IgnoreList
from .exclude import ExcludeList
from .exclude import ExcludeList as ExcludeList
from .scanner import ScanType
from .gui.deletion_options import DeletionOptions
from .gui.details_panel import DetailsPanel
Expand Down Expand Up @@ -139,10 +139,10 @@ def __init__(self, view):
os.makedirs(self.appdata)
self.app_mode = AppMode.Standard
self.discarded_file_count = 0
self.exclude_list = ExcludeList()
self.directories = directories.Directories()
self.results = results.Results(self)
self.ignore_list = IgnoreList()
self.exclude_list = ExcludeList(self)
# In addition to "app-level" options, this dictionary also holds options that will be
# sent to the scanner. They don't have default values because those defaults values are
# defined in the scanner class.
Expand Down
29 changes: 6 additions & 23 deletions core/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# http://www.gnu.org/licenses/gpl-3.0.html

import os
import re
from xml.etree import ElementTree as ET
import logging

Expand All @@ -14,6 +13,7 @@
from hscommon.util import FileOrPath

from . import fs
from .exclude import ExcludeList

__all__ = [
"Directories",
Expand Down Expand Up @@ -53,34 +53,17 @@ class Directories:
Then, when the user starts the scan, :meth:`get_files` is called to retrieve all files (wrapped
in :mod:`core.fs`) that have to be scanned according to the chosen folders/states.
"""
# FIXME: if there is zero item in these sets, the for each loops will yield NOTHING
deny_list_str = set()
deny_list_re = set()
deny_list_re_files = set()

# ---Override
def __init__(self):
def __init__(self, excluded=ExcludeList()):
self._dirs = []
# {path: state}
self.states = {}
self.deny_list_str.add(r".*Recycle\.Bin$")
self.deny_list_str.add(r"denyme.*")
self.deny_list_str.add(r".*denyme")
self.deny_list_str.add(r".*/test/denyme*")
self.deny_list_str.add(r".*/test/*denyme")
self.deny_list_str.add(r"denyme")
self.deny_list_str.add(r".*\/\..*")
self.deny_list_str.add(r"^\..*")
self.compile_re()

def compile_re(self):
for expr in self.deny_list_str:
try:
self.deny_list_re.add(re.compile(expr))
if os.sep not in expr:
self.deny_list_re_files.add(re.compile(expr))
except Exception as e:
logging.debug(f"Invalid regular expression \"{expr}\" in exclude list: {e}")
print(f"re_all: {self.deny_list_re}\nre_files: {self.deny_list_re_files}")
self._excluded = excluded

def __contains__(self, path):
for p in self._dirs:
Expand Down Expand Up @@ -217,15 +200,15 @@ def get_folders(self, folderclass=None, j=job.nulljob):
for folder in self._get_folders(from_folder, j):
yield folder

def get_state(self, path, denylist=deny_list_re):
def get_state(self, path, deny_list_re=deny_list_re):
"""Returns the state of ``path``.

:rtype: :class:`DirectoryState`
"""
# direct match? easy result.
if path in self.states:
return self.states[path]
state = self._default_state_for_path(path, denylist) or DirectoryState.Normal
state = self._default_state_for_path(path, deny_list_re) or DirectoryState.Normal
prevlen = 0
# we loop through the states to find the longest matching prefix
for p, s in self.states.items():
Expand Down
Loading