dev
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/.idea/
|
||||
**/__pycache__/
|
||||
/tests/
|
||||
poetry.lock
|
||||
1
README.md
Normal file
1
README.md
Normal file
@@ -0,0 +1 @@
|
||||
[nekomata is now in early-dev state](https://nekomata.kotikot.com/)
|
||||
6
neko_run_controller_std/__init__.py
Normal file
6
neko_run_controller_std/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .neko.interfaces import RunControllerHandlersInterface
|
||||
from .neko.types import CommandRunner, LogsHandler
|
||||
|
||||
|
||||
__all__ = [RunControllerHandlersInterface, CommandRunner, LogsHandler]
|
||||
__replacements__ = __all__
|
||||
1
neko_run_controller_std/neko/__init__.py
Normal file
1
neko_run_controller_std/neko/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
pass
|
||||
19
neko_run_controller_std/neko/interfaces.py
Normal file
19
neko_run_controller_std/neko/interfaces.py
Normal 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__
|
||||
67
neko_run_controller_std/neko/types.py
Normal file
67
neko_run_controller_std/neko/types.py
Normal 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
14
pyproject.toml
Normal 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"
|
||||
Reference in New Issue
Block a user