From d06ac42e64478c9f36e4d22c401401ac8196823f Mon Sep 17 00:00:00 2001 From: manuel83 Date: Fri, 7 Dec 2018 00:18:35 +0100 Subject: [PATCH] support static web content for plugins --- .idea/workspace.xml | 350 +++++++++++++------------- core/controller/plugin_controller.py | 5 +- core/craftbeerpi.py | 17 +- core/extension/comp/__init__.py | 5 +- core/extension/comp/static/index.html | 1 + craftbeerpi.db | Bin 53248 -> 53248 bytes 6 files changed, 199 insertions(+), 179 deletions(-) create mode 100644 core/extension/comp/static/index.html diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f201c04..3851efa 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,15 +3,9 @@ - - - - - - - + - - + + @@ -81,7 +75,7 @@ - + @@ -112,11 +106,11 @@ - + - - + + @@ -124,6 +118,16 @@ + + + + + + + + + + @@ -176,16 +180,6 @@ - - - - - - - - - - @@ -245,7 +239,6 @@ - - - - - - - - @@ -1558,47 +1562,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1612,14 +1575,6 @@ - - - - - - - - @@ -1638,25 +1593,82 @@ - + - - + + - + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/controller/plugin_controller.py b/core/controller/plugin_controller.py index 585b830..d33c94a 100644 --- a/core/controller/plugin_controller.py +++ b/core/controller/plugin_controller.py @@ -38,7 +38,7 @@ class PluginController(): data = yaml.load(await resp.text()) return data - async def load_plugins(self): + def load_plugins(self): for filename in os.listdir("./core/extension"): @@ -107,7 +107,8 @@ class PluginController(): print(self.cbpi.step.types) if issubclass(clazz, CBPiExtension): self.c = clazz(self.cbpi) - self.cbpi.register(self.c, "/dummy") + print("D###### DUMMY") + #self.cbpi.register(self.c, "/dummy") def _parse_props(self, cls): diff --git a/core/craftbeerpi.py b/core/craftbeerpi.py index 09f5edc..ee6a4e6 100644 --- a/core/craftbeerpi.py +++ b/core/craftbeerpi.py @@ -62,10 +62,12 @@ class CraftBeerPi(): self.kettle = KettleController(self) self.step = StepController(self) self.notification = NotificationController(self) - self.dummy = MyComp(self) + #self.dummy = MyComp(self) + self.login = Login(self) + self.plugin.load_plugins() self.register_events(self.ws) @@ -127,7 +129,7 @@ class CraftBeerPi(): for method in [getattr(obj, f) for f in dir(obj) if callable(getattr(obj, f)) and hasattr(getattr(obj, f), "ws")]: self.ws.add_callback(method, method.__getattribute__("key")) - def register(self, obj, url_prefix=None): + def register(self, obj, url_prefix=None, static=None): ''' This method parses the provided object @@ -136,13 +138,13 @@ class CraftBeerPi(): :param url_prefix: that prefix for HTTP Endpoints :return: None ''' - self.register_http_endpoints(obj, url_prefix) + self.register_http_endpoints(obj, url_prefix, static) self.register_events(obj) self.register_ws(obj) self.register_background_task(obj) self.register_on_startup(obj) - def register_http_endpoints(self, obj, url_prefix=None): + def register_http_endpoints(self, obj, url_prefix=None, static=None): ''' This method parses the provided object for @request_mapping decorator @@ -178,10 +180,14 @@ class CraftBeerPi(): switcher[http_method]() + + if url_prefix is not None: print("Prefx", url_prefix) sub = web.Application() sub.add_routes(routes) + if static is not None: + sub.add_routes([web.static('/static', static, show_index=True)]) self.app.add_subapp(url_prefix, sub) else: self.app.add_routes(routes) @@ -247,7 +253,8 @@ class CraftBeerPi(): async def load_plugins(app): #await PluginController.load_plugin_list() - await self.plugin.load_plugins() + #self.plugin.load_plugins() + pass async def call_initializer(app): diff --git a/core/extension/comp/__init__.py b/core/extension/comp/__init__.py index 7c589ce..345d4d5 100644 --- a/core/extension/comp/__init__.py +++ b/core/extension/comp/__init__.py @@ -23,8 +23,7 @@ class MyComp(CBPiExtension, CRUDController, HttpAPI): ''' self.cbpi = cbpi # register for bus events - self.cbpi.register(self, "/dummy") - + self.cbpi.register(self, "/dummy", static="./core/extension/comp/static") @on_event(topic="actor/#") @@ -48,5 +47,5 @@ def setup(cbpi): :return: ''' # regsiter the component to the core - #cbpi.plugin.register("MyComp", MyComp) + cbpi.plugin.register("MyComp", MyComp) pass \ No newline at end of file diff --git a/core/extension/comp/static/index.html b/core/extension/comp/static/index.html new file mode 100644 index 0000000..ab1afad --- /dev/null +++ b/core/extension/comp/static/index.html @@ -0,0 +1 @@ +HALLO WELT INDEX \ No newline at end of file diff --git a/craftbeerpi.db b/craftbeerpi.db index b8ae745f74768540c56054b5ee3864e9292e549d..97baeb7f954fd1cc5a57bf3c007461c8a9a14ffd 100644 GIT binary patch delta 58 zcmZozz}&Ead4e=!z(g5m)&K@QjqHsn3-)s`@xNi<|Hl7jv!K8Oei05PW(ILz$52-v N4n`m=+~42B9{>k*58wa* delta 46 zcmZozz}&Ead4e>f|3n#QR(}RPR>zGg3-+@y@_%FC|F&6B;0-?)2O~3sc(}j6hd%&E CvkeCT