commit 3eb13a369b68da9b1de868f278b5e92914aed568 Author: hhh Date: Sat Jan 4 11:55:47 2025 +0200 dev diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4422f8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.idea/ +**/__pycache__/ +/tests/ +poetry.lock \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4267334 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +[nekomata is now in early-dev state](https://nekomata.kotikot.com/) diff --git a/neko_run_controller_std/__init__.py b/neko_run_controller_std/__init__.py new file mode 100644 index 0000000..603ad81 --- /dev/null +++ b/neko_run_controller_std/__init__.py @@ -0,0 +1,6 @@ +from .neko.interfaces import RunControllerHandlersInterface +from .neko.types import CommandRunner, LogsHandler + + +__all__ = [RunControllerHandlersInterface, CommandRunner, LogsHandler] +__replacements__ = __all__ diff --git a/neko_run_controller_std/neko/__init__.py b/neko_run_controller_std/neko/__init__.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/neko_run_controller_std/neko/__init__.py @@ -0,0 +1 @@ +pass diff --git a/neko_run_controller_std/neko/interfaces.py b/neko_run_controller_std/neko/interfaces.py new file mode 100644 index 0000000..81f2b3f --- /dev/null +++ b/neko_run_controller_std/neko/interfaces.py @@ -0,0 +1,19 @@ +from abc import ABC, abstractmethod +from .types import LogsHandler +from typing import Type + + +class RunControllerHandlersInterface(ABC): + @staticmethod + @abstractmethod + def add_logs_handler(handler: Type[LogsHandler]): + """ + When creating CommandRunner, every LogsHandler passed here will be initialized + with this new CommandRunner passed in it + :param handler: Implementation class of LogsHandler + :return: + """ + + +__all__ = [RunControllerHandlersInterface] +__replacements__ = __all__ diff --git a/neko_run_controller_std/neko/types.py b/neko_run_controller_std/neko/types.py new file mode 100644 index 0000000..bee8325 --- /dev/null +++ b/neko_run_controller_std/neko/types.py @@ -0,0 +1,67 @@ +from abc import abstractmethod, ABC + + +class CommandRunner(ABC): + name: str + command: str + env: dict = None + chdir: str = None + + def __init__(self, name: str, command: str, env: dict = None, chdir: str = None): + """ + :param name: Unique name or id for runner + :param command: Command to run + :param env: Environment, will be system env by default, but passing this value + will overwrite the environment, so add os.environ to the dictionary if required + :param chdir: Changes directory to specified + """ + ... + + @abstractmethod + async def start(self): + """ + Run selected command in new thread + :return: + """ + + @abstractmethod + async def wait(self): + """ + Wait for process to finish + :return: + """ + + @abstractmethod + async def kill(self): + """ + Kill this subprocess + :return: + """ + + +class LogsHandler(ABC): + runner: CommandRunner + + def __init__(self, runner: CommandRunner): + """ + :param runner: Will be passed when creating handler + """ + self.runner = runner + + async def stdout(self, line: str): + """ + Called on stdout line + :param line: Logs string + :return: + """ + + async def stderr(self, line: str): + """ + Called on stderr line + :param line: Logs string + :return: + """ + + +__all__ = [CommandRunner, LogsHandler] +__replacements__ = __all__ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b04a972 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "neko-run-controller-std" +version = "0.1.0" +description = "" +authors = ["hhh "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.11" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"