This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExecutorFactory: | |
| """ The factory class for creating executors""" | |
| registry = {} | |
| """ Internal registry for available executors """ | |
| @classmethod | |
| def register(cls, name: str) -> Callable: | |
| def inner_wrapper(wrapped_class: ExecutorBase) -> Callable: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExecutorFactory: | |
| """ The factory class for creating executors""" | |
| registry = {} | |
| """ Internal registry for available executors """ | |
| @classmethod | |
| def create_executor(cls, name: str, **kwargs) -> 'ExecutorBase': | |
| """ Factory command to create the executor """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| executor = LocalExecutor() | |
| stdout, _ = executor.run('ls -ltr') | |
| print(stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LocalExecutor(ExecutorBase): | |
| def run(self, command: str) -> (str, str): | |
| """ Runs the given command using subprocess """ | |
| args = shlex.split(command) | |
| stdout, stderr = subprocess.Popen(args, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE).communicate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ExecutorBase(metaclass=ABCMeta): | |
| """ Base class for an executor """ | |
| def __init__(self, **kwargs): | |
| """ Constructor """ | |
| pass | |
| @abstractmethod | |
| def run(self, command: str) -> (str, str): | |
| """ Abstract method to run a command """ |
NewerOlder