Files
project-manager/project_manager/entry.py
T
2023-03-15 10:26:33 +03:00

49 lines
1.1 KiB
Python

__all__ = (
"EntryCommandNotImplementedError",
"Entry",
)
import logging
from pathlib import Path
from typing import Dict, List, Optional
from .command import Command
logger = logging.getLogger("entry")
class EntryCommandNotImplementedError(NotImplementedError):
pass
class Entry:
_logger = logger
def __init__(
self,
entry_type: str,
commands: Dict[str, List[List[str]]],
basepath: Path,
):
self._type = entry_type
self._commands = commands
self._basepath = basepath
def run_command(self, command_name: str):
if command_name == "show":
self._logger.info(f"{self}")
return
self._logger.info(f"{command_name} {self}")
if command_name not in self._commands:
raise EntryCommandNotImplementedError(command_name)
for command in self._commands[command_name]:
Command(*command).run(self._basepath)
def __repr__(self):
return f"{self._type} {str(self._basepath)}"
@classmethod
def detect(cls, basepath: Path) -> Optional["Entry"]:
raise NotImplemented