From 28b202cf305fecb60576e43e3328036e198cfdff Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 19 Oct 2020 13:16:23 +0200 Subject: [PATCH] Detect version of plugins from setup.py, updated Readme --- flaschengeist/modules/__init__.py | 4 +++- flaschengeist/readme.md | 33 ++++++++++++------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/flaschengeist/modules/__init__.py b/flaschengeist/modules/__init__.py index e84ac55..806bd95 100644 --- a/flaschengeist/modules/__init__.py +++ b/flaschengeist/modules/__init__.py @@ -1,3 +1,5 @@ +import pkg_resources + from flaschengeist.system.hook import HookCall send_message_hook = HookCall("send_message") @@ -7,7 +9,7 @@ class Plugin: def __init__(self, config=None, blueprint=None, permissions={}): self.blueprint = blueprint self.permissions = permissions - self.version = "dummy" + self.version = pkg_resources.get_distribution(self.__module__.split(".")[0]).version def install(self): """Installation routine diff --git a/flaschengeist/readme.md b/flaschengeist/readme.md index e3dc10c..d860d7c 100644 --- a/flaschengeist/readme.md +++ b/flaschengeist/readme.md @@ -68,23 +68,18 @@ Or if you just want to use `git blame`, configure git like this: example_bp = Blueprint("example", __name__, url_prefix="/example") permissions = {"EXAMPLE_HELLO": "example_hello"} - - def register(): - # If no model is needed: - # return Plugin(schedule_bp, permissions) - # else if model is used: - class ExamplePlugin(Plugin): - def install(self): - from flaschengeist.system.database import db - import .model - db.create_all() - db.session.commit() - - return ExamplePlugin(schedule_bp, permissions) - - - - @schedule_bp.route("/hello", methods=['GET']) + class PluginExample(Plugin): + def __init__(self, conf): + super().__init__(blueprint=example_bp, permissions=permissions) + + def install(self): + from flaschengeist.system.database import db + import .model + db.create_all() + db.session.commit() + + + @example_bp.route("/hello", methods=['GET']) @login_required(roles=['example_hello']) def __hello(id, **kwargs): return "Hello" @@ -94,8 +89,6 @@ Optional, only needed if you need your own models (database) from flaschengeist.system.database import db - model_name = __name__ - class ExampleModel(db.Model): """Example Model""" @@ -115,7 +108,7 @@ Optional, only needed if you need your own models (database) ], entry_points={ "flaschengeist.plugin": [ - "example = flaschengeist-example-plugin:register" "roles = flaschengeist.modules.roles:register", + "example = flaschengeist-example-plugin:ExampleModel" ] }, )