feat: add manager, entry and command

This commit is contained in:
2023-03-13 00:06:21 +03:00
parent a8788fbaf9
commit ccdbb00eff
11 changed files with 244 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
from pathlib import Path
from typing import Iterable, Optional, Type
from .entry import Entry
__all__ = (
"EntryDetector",
"EntryResolver",
)
class EntryDetector:
def __init__(self, *entry_types: Type[Entry]):
self._entry_types = entry_types
def detect(self, basepath: Path) -> Optional[Entry]:
for entry_type in self._entry_types:
entry = entry_type.detect(basepath)
if entry:
return entry
class EntryResolver:
def __init__(self, detector: EntryDetector):
self._detector = detector
def resolve(self, basepath: Path, depth: int = 2) -> Iterable[Entry]:
if basepath.is_dir():
entry = self._detector.detect(basepath)
if entry:
yield entry
if depth > 0 and basepath.is_dir():
for path in basepath.iterdir():
yield from self.resolve(path, depth - 1)