51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
import logging
|
|
from pathlib import Path
|
|
from typing import NamedTuple
|
|
|
|
from ..common.command import CommandExecutor
|
|
|
|
logger = logging.getLogger("entry")
|
|
|
|
|
|
class TaskKey(NamedTuple):
|
|
name: str
|
|
tag: str
|
|
|
|
def __repr__(self) -> str:
|
|
return f"{self.name}:{self.tag}"
|
|
|
|
|
|
class Entry:
|
|
_logger = logger
|
|
|
|
def __init__(
|
|
self,
|
|
tasks: dict[TaskKey, list[str]],
|
|
basepath: Path,
|
|
):
|
|
self._tasks = tasks
|
|
self._basepath = basepath
|
|
|
|
def show(self):
|
|
self._logger.info("🔵 %s", self)
|
|
for task_name, commands in self._tasks.items():
|
|
self._logger.info(" %s", task_name)
|
|
for command in commands:
|
|
self._logger.debug(" %s", command)
|
|
|
|
def run_task(self, task_name: str, tag: str | None = None) -> bool:
|
|
if task_name == "show":
|
|
self.show()
|
|
return True
|
|
runned = False
|
|
for task_key, commands in self._tasks.items():
|
|
if task_key.name == task_name and (tag is None or tag == task_key.tag):
|
|
self._logger.info("🔵 %s %s", task_key, self)
|
|
runned = True
|
|
for command in commands:
|
|
CommandExecutor(command).run(self._basepath)
|
|
return runned
|
|
|
|
def __repr__(self):
|
|
return f"{str(self._basepath)}"
|