aboutsummaryrefslogtreecommitdiff
path: root/src/ModuleManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-29 09:23:40 +0100
committerGravatar jesopo2018-09-29 09:23:40 +0100
commit0f7a122a8447f0b0e9b7d2ef3f57869a277b0348 (patch)
tree6ac576fd2b357138dda8cc2f130c202803a4f1ed /src/ModuleManager.py
parentCorrect syntax of event call in Timers.call (diff)
signature
Move hashflag parsing to Utils.get_hashflags
Diffstat (limited to 'src/ModuleManager.py')
-rw-r--r--src/ModuleManager.py44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index c9aa650a..1eada688 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -1,4 +1,5 @@
import glob, imp, io, inspect, os, sys, uuid
+from src import Utils
BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
@@ -53,31 +54,24 @@ class ModuleManager(object):
def _load_module(self, bot, name):
path = self._module_path(name)
- with io.open(path, mode="r", encoding="utf8") as module_file:
- while True:
- line = module_file.readline().strip()
- line_split = line.split(" ")
- if line and line.startswith("#--"):
- # this is a hashflag
- if line == "#--ignore":
- # nope, ignore this module.
- raise ModuleNotLoadedWarning("module ignored")
- elif line_split[0] == "#--require-config" and len(
- line_split) > 1:
- if not self.config.get(line_split[1].lower(), None):
- # nope, required config option not present.
- raise ModuleNotLoadedWarning(
- "required config not present")
- elif line_split[0] == "#--require-module" and len(
- line_split) > 1:
- if not "bitbot_%s" % line_split[1].lower() in sys.modules:
- if not line_split[1].lower() in self.waiting_requirement:
- self.waiting_requirement[line_split[1].lower()] = set([])
- self.waiting_requirement[line_split[1].lower()].add(path)
- raise ModuleNotLoadedWarning(
- "waiting for requirement")
- else:
- break
+ for hashflag, value in Utils.get_hashflags(path):
+ if hashflag == "ignore":
+ # nope, ignore this module.
+ raise ModuleNotLoadedWarning("module ignored")
+
+ elif hashflag == "require-config" and value:
+ if not self.config.get(value.lower(), None):
+ # nope, required config option not present.
+ raise ModuleNotLoadedWarning("required config not present")
+
+ elif hashflag == "require-module" and value:
+ requirement = value.lower()
+ if not requirement in self.modules:
+ if not requirement in self.waiting_requirement:
+ self.waiting_requirement[requirement] = set([])
+ self.waiting_requirement[requirement].add(path)
+ raise ModuleNotLoadedWarning("waiting for requirement")
+
module = imp.load_source(self._import_name(name), path)
if not hasattr(module, "Module"):