Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b763308aa9 | |||
| 34ba757bc6 | |||
| b5d2e1b0be | |||
| d3031952bf | |||
| 3312f2da28 | |||
| a21122671d | |||
| 9effa4be3e | |||
| 217038b863 | |||
| 8c19c4a97b | |||
| c7662a5d47 |
+5
-1
@@ -16,6 +16,10 @@ if __name__ == "__main__":
|
||||
"""
|
||||
system = XtendRSystem()
|
||||
system.attach("example_plugin") # Assuming 'example_plugin/plugin_info.json' exists
|
||||
system.run("example_plugin")
|
||||
system.run("example_plugin", "Hello!")
|
||||
system.stop("example_plugin")
|
||||
system.run("example_plugin", 25)
|
||||
system.stop("example_plugin")
|
||||
system.run("example_plugin", "Hello!", 25)
|
||||
system.stop("example_plugin")
|
||||
system.detach("example_plugin")
|
||||
@@ -5,12 +5,19 @@ class ExamplePlugin(XtendRBase):
|
||||
|
||||
Example:
|
||||
>>> plugin = ExamplePlugin()
|
||||
>>> plugin.run()
|
||||
>>> plugin.run("Hello!", 25)
|
||||
Passed arguments 2:
|
||||
Argument 0: Hello!
|
||||
Argument 1: 25
|
||||
ExamplePlugin is running!
|
||||
>>> plugin.stop()
|
||||
ExamplePlugin has stopped!
|
||||
"""
|
||||
def run(self):
|
||||
def run(self, *args):
|
||||
print(f"Passed arguments {len(args)}:")
|
||||
for idx, a in enumerate(args):
|
||||
print(f"Argument {idx}: {a}")
|
||||
|
||||
print("ExamplePlugin is running!")
|
||||
|
||||
def stop(self):
|
||||
|
||||
@@ -3,7 +3,7 @@ if __name__ == "__main__":
|
||||
|
||||
setup(
|
||||
name="XtendR",
|
||||
version="0.0.9",
|
||||
version="0.2.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
author="Jan Lerking",
|
||||
|
||||
@@ -17,7 +17,7 @@ class XtendRBase(ABC):
|
||||
Stopping TestPlugin
|
||||
"""
|
||||
@abstractmethod
|
||||
def run(self):
|
||||
def run(self, *args):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
|
||||
+12
-3
@@ -4,11 +4,15 @@ import os
|
||||
import json
|
||||
from xtendr.xtendrbase import XtendRBase
|
||||
|
||||
__version__ = "0.1.3"
|
||||
|
||||
class XtendRSystem:
|
||||
"""Plugin system to manage plugins.
|
||||
|
||||
Example:
|
||||
>>> system = XtendRSystem()
|
||||
>>> system.version()
|
||||
XtendR v0.1.3
|
||||
>>> system.attach("example_plugin") # Assuming 'example_plugin/example_plugin.json' exists
|
||||
>>> system.run("example_plugin")
|
||||
ExamplePlugin is running!
|
||||
@@ -17,16 +21,20 @@ class XtendRSystem:
|
||||
>>> system.detach("example_plugin")
|
||||
Detached plugin 'example_plugin'.
|
||||
"""
|
||||
def __init__(self):
|
||||
def __init__(self, pluginpath = "plugins"):
|
||||
self.pluginspath = pluginpath
|
||||
self.plugins = {}
|
||||
|
||||
def version(self) -> str:
|
||||
return "XtendR v" + __version__
|
||||
|
||||
def attach(self, name: str) -> None:
|
||||
"""Dynamically load a plugin from its folder."""
|
||||
if name in self.plugins:
|
||||
print(f"Plugin '{name}' is already attached.")
|
||||
return
|
||||
|
||||
plugin_path = os.path.join(os.getcwd(), "plugins", name)
|
||||
plugin_path = os.path.join(os.getcwd(), self.pluginspath, name)
|
||||
info_path = os.path.join(plugin_path, name + ".json")
|
||||
print(plugin_path + "\n" + info_path)
|
||||
|
||||
@@ -55,7 +63,8 @@ class XtendRSystem:
|
||||
self.plugins[name] = {
|
||||
'instance': instance,
|
||||
'running': False,
|
||||
'info': plugin_info
|
||||
'info': plugin_info,
|
||||
'autorun': False
|
||||
}
|
||||
print(f"Attached plugin '{name}'.")
|
||||
except (ModuleNotFoundError, json.JSONDecodeError, AttributeError) as e:
|
||||
|
||||
Reference in New Issue
Block a user