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

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__