feat: rework default entries

This commit is contained in:
2023-03-15 10:26:33 +03:00
parent 9345b27aef
commit 23ca8c0cac
14 changed files with 101 additions and 116 deletions
+12 -6
View File
@@ -3,9 +3,10 @@ from collections import Counter
from pathlib import Path
from typing import Dict, Iterable
from .command import CommandError
from .entries.nodejs import NodejsEntry
from .entries.python import PythonEntry
from .entry import Entry, EntryCommandNotImplementedError
from .nodejs.entry import NodejsEntry
from .python.entry import PythonEntry
from .resolver import EntryDetector, EntryResolver
__all__ = ("ProjectManager",)
@@ -18,20 +19,25 @@ class ProjectManager:
def __init__(self, basepath: Path):
self._basepaht = basepath
self._resolver = EntryResolver(EntryDetector(PythonEntry, NodejsEntry))
self._resolver = EntryResolver(
EntryDetector(PythonEntry, NodejsEntry), ["node_modules", ".venv", ".git"]
)
def _iter_entries(self) -> Iterable[Entry]:
return self._resolver.resolve(self._basepaht)
def run_command(self, command: str) -> Dict[str, int]:
def run_command(self, command_name: str) -> Dict[str, int]:
counter = Counter()
for entry in self._iter_entries():
try:
getattr(entry, command)()
entry.run_command(command_name)
counter["success"] += 1
except EntryCommandNotImplementedError:
self._logger.warn(f"{command} {entry}")
self._logger.warn(f"{command_name} {entry}")
counter["skipped"] += 1
except CommandError as error:
self._logger.error(f"{entry}\n{error.output}")
counter["failed"] += 1
except Exception:
self._logger.exception(entry)
counter["failed"] += 1