Skip to content

Commit 17a725d

Browse files
committed
Added logic to blacklist files and folders based on provided substrings; added 'substrings_blacklist' as an attribute to the DirWatcher class
1 parent 5b796b3 commit 17a725d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/murfey/client/watchdir.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(
3232
path: str | os.PathLike,
3333
settling_time: float = 60,
3434
appearance_time: float | None = None,
35+
substrings_blacklist: dict[str, dict] = {},
3536
transfer_all: bool = True,
3637
status_bar: StatusBar | None = None,
3738
):
@@ -42,6 +43,7 @@ def __init__(
4243
self._statusbar = status_bar
4344
self.settling_time = settling_time
4445
self._appearance_time = appearance_time
46+
self._substrings_blacklist = substrings_blacklist
4547
self._transfer_all = transfer_all
4648
self._modification_overwrite: float | None = None
4749
self._init_time: float = time.time()
@@ -252,15 +254,26 @@ def _scan_directory(
252254
raise
253255
for entry in directory_contents:
254256
entry_name = os.path.join(path, entry.name)
255-
if entry.is_dir() and (
257+
# Skip any directories with matching blacklisted substrings
258+
if entry.is_dir() and any(
259+
char in entry.name
260+
for char in self._substrings_blacklist.get("directories", [])
261+
):
262+
continue
263+
elif entry.is_dir() and (
256264
modification_time is None or entry.stat().st_ctime >= modification_time
257265
):
258266
result.update(self._scan_directory(entry_name))
259267
else:
260268
# Exclude textual log
261269
if "textual" in str(entry):
262270
continue
263-
271+
# Exclude files with blacklisted substrings
272+
if any(
273+
char in entry.name
274+
for char in self._substrings_blacklist.get("files", [])
275+
):
276+
continue
264277
# Get file statistics and append file to dictionary
265278
try:
266279
file_stat = entry.stat()

0 commit comments

Comments
 (0)