added predefine feature (to be documented in README)
This commit is contained in:
parent
30f53c08d4
commit
f6e744a14d
19
main.py
19
main.py
|
@ -21,17 +21,27 @@ def readfile(filename):
|
||||||
|
|
||||||
# module object classes
|
# module object classes
|
||||||
class ModuleV1:
|
class ModuleV1:
|
||||||
def __init__(self, path, code, enabled, alias):
|
def __init__(self, path, code, enabled, alias, predefine):
|
||||||
self.version = 1
|
self.version = 1
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.code = code
|
self.code = code
|
||||||
self.alias = alias
|
self.alias = alias
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.predefine = predefine
|
||||||
|
|
||||||
|
if self.predefine:
|
||||||
|
self.predefine()
|
||||||
|
|
||||||
# set environmental variables
|
# set environmental variables
|
||||||
def set_env(self):
|
def set_env(self):
|
||||||
self.RESPONCE = ""
|
self.RESPONCE = ""
|
||||||
|
|
||||||
|
def predefine(self):
|
||||||
|
try:
|
||||||
|
exec(self.predefine)
|
||||||
|
except Exception as e:
|
||||||
|
print("[ERROR] module: module \"{}\" ({}) raised exception \"{}\" during predefine stage, disabling it...".format(self.path, self.alias, e))
|
||||||
|
|
||||||
# running the module
|
# running the module
|
||||||
def process(self, msg):
|
def process(self, msg):
|
||||||
self.set_env()
|
self.set_env()
|
||||||
|
@ -83,7 +93,12 @@ class ModuleControlUnit:
|
||||||
else:
|
else:
|
||||||
alias = None
|
alias = None
|
||||||
|
|
||||||
self.modules.append( ModuleV1( "modules/{}/".format(folder), code, enabled, alias ) )
|
if "predefine" in meta:
|
||||||
|
predefine = readfile("modules/{}/{}".format(folder, meta["predefine"]))
|
||||||
|
else:
|
||||||
|
predefine = False
|
||||||
|
|
||||||
|
self.modules.append( ModuleV1( "modules/{}/".format(folder), code, enabled, alias, predefine ) )
|
||||||
|
|
||||||
print("[INFO] reload_modules: successfully loaded {} as {} (start_on_boot: {})".format(folder, alias, enabled))
|
print("[INFO] reload_modules: successfully loaded {} as {} (start_on_boot: {})".format(folder, alias, enabled))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue