central skip

This commit is contained in:
lelo 2026-01-24 15:18:50 +00:00
parent 063f14a7b4
commit c8c0db493f

View File

@ -9,6 +9,7 @@ from collections import defaultdict
SEARCH_DB_NAME = 'search.db' SEARCH_DB_NAME = 'search.db'
ACCESS_LOG_DB_NAME = 'access_log.db' ACCESS_LOG_DB_NAME = 'access_log.db'
FOLDER_CONFIG = 'folder_secret_config.json' FOLDER_CONFIG = 'folder_secret_config.json'
IGNORED_DIRS = {"Transkription", "@eaDir", ".app", "#recycle"}
# Connect to the search database. # Connect to the search database.
search_db = sqlite3.connect(SEARCH_DB_NAME, check_same_thread=False) search_db = sqlite3.connect(SEARCH_DB_NAME, check_same_thread=False)
@ -22,6 +23,11 @@ def log(message: str):
"""Small helper to ensure console output is flushed immediately.""" """Small helper to ensure console output is flushed immediately."""
print(message, flush=True) print(message, flush=True)
def skip_dir(name: str) -> bool:
"""Return True when a directory name should be skipped during traversal/logging."""
return name.startswith('.') or name in IGNORED_DIRS
def init_db(): def init_db():
"""Initializes the database with the required schema.""" """Initializes the database with the required schema."""
cursor = search_db.cursor() cursor = search_db.cursor()
@ -60,9 +66,7 @@ def scan_dir(directory):
for entry in it: for entry in it:
if entry.is_dir(follow_symlinks=False): if entry.is_dir(follow_symlinks=False):
# Skip unwanted directories immediately. # Skip unwanted directories immediately.
if entry.name.startswith(('.', '@', '#')): if skip_dir(entry.name):
continue
if entry.name.lower() in {"transkription", ".app", "#recycle"}:
continue continue
yield from scan_dir(entry.path) yield from scan_dir(entry.path)
elif entry.is_file(follow_symlinks=False): elif entry.is_file(follow_symlinks=False):
@ -106,9 +110,7 @@ def log_structure(root_path, max_depth=None, show_files=False):
entries = sorted(it, key=lambda e: (not e.is_dir(follow_symlinks=False), e.name.lower())) entries = sorted(it, key=lambda e: (not e.is_dir(follow_symlinks=False), e.name.lower()))
for entry in entries: for entry in entries:
if entry.is_dir(follow_symlinks=False): if entry.is_dir(follow_symlinks=False):
if entry.name.startswith(('.')): if skip_dir(entry.name):
continue
if entry.name in {"Transkription", "@eaDir", ".app", "#recycle"}:
continue continue
indent = " " * (depth - 1) indent = " " * (depth - 1)
log(f"{indent}- {entry.name}/") log(f"{indent}- {entry.name}/")