upload volledige repo

This commit is contained in:
kodi
2026-03-11 09:39:41 +01:00
commit ce420cbb0e
110 changed files with 5660 additions and 0 deletions
@@ -0,0 +1,61 @@
from __future__ import annotations
import shutil
from datetime import datetime, timezone
from pathlib import Path
class FilesystemAdapter:
def list_directory(self, directory: Path, show_hidden: bool) -> tuple[list[dict], list[dict]]:
directories: list[dict] = []
files: list[dict] = []
for entry in sorted(directory.iterdir(), key=lambda item: item.name.lower()):
if not show_hidden and entry.name.startswith("."):
continue
stat = entry.stat()
modified = datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc).isoformat().replace("+00:00", "Z")
if entry.is_dir():
directories.append({"name": entry.name, "modified": modified, "absolute": entry})
elif entry.is_file():
files.append(
{
"name": entry.name,
"size": int(stat.st_size),
"modified": modified,
"absolute": entry,
}
)
return directories, files
def make_directory(self, path: Path) -> None:
path.mkdir(parents=False, exist_ok=False)
def rename_path(self, source: Path, destination: Path) -> None:
source.rename(destination)
def move_file(self, source: str, destination: str) -> None:
Path(source).rename(Path(destination))
def is_directory_empty(self, path: Path) -> bool:
return not any(path.iterdir())
def delete_file(self, path: Path) -> None:
path.unlink()
def delete_empty_directory(self, path: Path) -> None:
path.rmdir()
def copy_file(self, source: str, destination: str, on_progress: callable | None = None) -> None:
src = Path(source)
dst = Path(destination)
with src.open("rb") as in_f, dst.open("xb") as out_f:
while True:
chunk = in_f.read(1024 * 1024)
if not chunk:
break
out_f.write(chunk)
if on_progress:
on_progress(out_f.tell())
shutil.copystat(src, dst, follow_symlinks=False)