This commit is contained in:
hhh
2025-01-04 11:55:47 +02:00
commit 3eb13a369b
7 changed files with 112 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/.idea/
**/__pycache__/
/tests/
poetry.lock

1
README.md Normal file
View File

@@ -0,0 +1 @@
[nekomata is now in early-dev state](https://nekomata.kotikot.com/)

View File

@@ -0,0 +1,6 @@
from .neko.interfaces import RunControllerHandlersInterface
from .neko.types import CommandRunner, LogsHandler
__all__ = [RunControllerHandlersInterface, CommandRunner, LogsHandler]
__replacements__ = __all__

View File

@@ -0,0 +1 @@
pass

View File

@@ -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__

View File

@@ -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__

14
pyproject.toml Normal file
View File

@@ -0,0 +1,14 @@
[tool.poetry]
name = "neko-run-controller-std"
version = "0.1.0"
description = ""
authors = ["hhh <h@localhost>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"