aboutsummaryrefslogtreecommitdiff
path: root/src/ModuleManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-27 11:45:23 +0100
committerGravatar jesopo2018-09-27 11:45:23 +0100
commitf3d98d0e95bbd43202c00f836aef663d249a47a6 (patch)
tree560d74748d7d76f4b98c6e1d7a1ed14c449cf4ff /src/ModuleManager.py
parentDon't give IRCBot instance to things that don't need it, use a better way of (diff)
signature
Implement @Utils.export, to denote an export on a module
Diffstat (limited to 'src/ModuleManager.py')
-rw-r--r--src/ModuleManager.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index 6f178a16..dfcfc409 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -1,6 +1,7 @@
import glob, imp, inspect, os, sys, uuid
BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
+BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
class ModuleException(Exception):
pass
@@ -41,6 +42,9 @@ class ModuleManager(object):
def _import_name(self, name):
return "bitbot_%s" % name
+ def _get_magic(self, obj, magic, default):
+ return getattr(obj, magic) if hasattr(obj, magic) else default
+
def _load_module(self, name):
path = self._module_path(name)
@@ -89,12 +93,11 @@ class ModuleManager(object):
module_object._name = name.title()
for attribute_name in dir(module_object):
attribute = getattr(module_object, attribute_name)
- if inspect.ismethod(attribute) and hasattr(attribute,
- BITBOT_HOOKS_MAGIC):
- hooks = getattr(attribute, BITBOT_HOOKS_MAGIC)
- for hook in hooks:
- context_events.on(hook["event"]).hook(attribute,
- docstring=attribute.__doc__, **hook["kwargs"])
+ for hook in self._get_magic(attribute, BITBOT_HOOKS_MAGIC, []):
+ context_events.on(hook["event"]).hook(attribute,
+ docstring=attribute.__doc__, **hook["kwargs"])
+ for export in self._get_magic(module_object, BITBOT_EXPORTS_MAGIC, []):
+ context_exports.add(export["setting"], export["value"])
module_object._context = context
module_object._import_name = name