dev
This commit is contained in:
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__
|
||||
Reference in New Issue
Block a user