scanner code v1 & new libs

This commit is contained in:
2026-03-31 00:43:39 +03:00
parent 67ca2a8b63
commit 734c3bfff1
79 changed files with 6630 additions and 0 deletions

41
core/scanner.py Normal file
View File

@@ -0,0 +1,41 @@
import os
import lib.hashlib as hashlib
from lib.pathlib import Path
from lib.pathspec import PathSpec
class Scanner:
def __init__(self, base_path, ignore_file=".syncignore", include_file=".syncinclude"):
self.base_path = Path(base_path)
self.ignore_file = self._load_ignore_spec(ignore_file)
self.include_file= self._load_include_spec(include_file)
def _load_ignore_spec(self, file):
pass
def _load_include_spec(self, file):
pass
def get_current_state(self):
state = {}
for root , dirs, files in os.walk(self.base_path):
dirs[:] = [d for d in dirs if not self.spec.match_file(str(Path(root, d).relative_to(self.base_path)))]
for file in files:
full_path = Path(root) / file
rel_path = str(full_path.relative_to(self.base_path))
if not self.spec.match_file(rel_path):
state[rel_path] = self._hash_file(rel_path)
return state
def _hash_file(self, path)
return hashlib.md5(open(path, 'rb').read()).hexdigest()