Add files via upload
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .pyxtend_registry import PyXtendCore, IPyXtendRegistry
|
||||
from .pyxtend_core import PyXtendEngine
|
||||
from .pyxtend_core import PyXtendEngine
|
||||
from .pyxtend_models import Meta, Device, PluginConfig, DependencyModule, PyXtendRunTimeOption
|
||||
@@ -0,0 +1,31 @@
|
||||
from logging import Logger
|
||||
|
||||
from usecase import PluginUseCase
|
||||
from util import LogUtil
|
||||
|
||||
|
||||
class PyXtendEngine:
|
||||
_logger: Logger
|
||||
|
||||
def __init__(self, **args) -> None:
|
||||
self._logger = LogUtil.create(args['options']['log_level'])
|
||||
self.use_case = PluginUseCase(args['options'])
|
||||
|
||||
def start(self) -> None:
|
||||
self.__reload_plugins()
|
||||
self.__invoke_on_plugins('Q')
|
||||
|
||||
def __reload_plugins(self) -> None:
|
||||
"""Reset the list of all plugins and initiate the walk over the main
|
||||
provided plugin package to load all available plugins
|
||||
"""
|
||||
self.use_case.discover_plugins(True)
|
||||
|
||||
def __invoke_on_plugins(self, command: chr):
|
||||
"""Apply all of the plugins on the argument supplied to this function
|
||||
"""
|
||||
for module in self.use_case.modules:
|
||||
plugin = self.use_case.register_plugin(module, self._logger)
|
||||
delegate = self.use_case.hook_plugin(plugin)
|
||||
device = delegate(command=command)
|
||||
self._logger.info(f'Loaded device: {device}')
|
||||
@@ -0,0 +1,36 @@
|
||||
from logging import Logger
|
||||
from typing import Optional, List
|
||||
|
||||
from model import Meta, Device
|
||||
|
||||
|
||||
class IPyXtendRegistry(type):
|
||||
plugin_registries: List[type] = list()
|
||||
|
||||
def __init__(cls, name, bases, attrs):
|
||||
super().__init__(cls)
|
||||
if name != 'PluginCore':
|
||||
IPyXtendRegistry.plugin_registries.append(cls)
|
||||
|
||||
|
||||
class PyXtendCore(object, metaclass=IPyXtendRegistry):
|
||||
"""
|
||||
Plugin core class
|
||||
"""
|
||||
|
||||
meta: Optional[Meta]
|
||||
|
||||
def __init__(self, logger: Logger) -> None:
|
||||
"""
|
||||
Entry init block for plugins
|
||||
:param logger: logger that plugins can make use of
|
||||
"""
|
||||
self._logger = logger
|
||||
|
||||
def invoke(self, **args) -> Device:
|
||||
"""
|
||||
Starts main plugin flow
|
||||
:param args: possible arguments for the plugin
|
||||
:return: a device for the plugin
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user