Reworking module naming conventions. #5
22
main.py
22
main.py
|
@ -57,13 +57,13 @@ class ModuleV1:
|
|||
return ""
|
||||
|
||||
class ModuleV2:
|
||||
def __init__(self, path, index_file, enabled, alias):
|
||||
def __init__(self, path, module_file, enabled, alias):
|
||||
self.version = 2
|
||||
self.enabled = enabled
|
||||
self.alias = alias
|
||||
self.path = path
|
||||
self.index_file = index_file[:-3]
|
||||
self.obj = importlib.import_module((path + self.index_file).replace("/", "."))
|
||||
self.module_file = module_file[:-3]
|
||||
self.obj = importlib.import_module((path + self.module_file).replace("/", "."))
|
||||
|
||||
# running the module
|
||||
def process(self, msg):
|
||||
|
@ -94,12 +94,12 @@ class ModuleControlUnit:
|
|||
meta = json.loads( meta_raw )
|
||||
if "version" in meta:
|
||||
if meta["version"] == 1:
|
||||
if "index_file" in meta:
|
||||
index_file = meta["index_file"]
|
||||
if "module_file" in meta:
|
||||
module_file = meta["module_file"]
|
||||
else:
|
||||
index_file = "index.py"
|
||||
module_file = "main.py"
|
||||
|
||||
code = readfile( "modules/{}/{}".format(folder, index_file) )
|
||||
code = readfile( "modules/{}/{}".format(folder, module_file) )
|
||||
if not code: # False both when readfile() returns False and when the code string is empty
|
||||
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
||||
continue
|
||||
|
@ -124,10 +124,10 @@ class ModuleControlUnit:
|
|||
print("[INFO] reload_modules: successfully loaded {} as {} (start_on_boot: {})".format(folder, alias, enabled))
|
||||
|
||||
elif meta["version"] == 2:
|
||||
if "index_file" in meta:
|
||||
index_file = meta["index_file"]
|
||||
if "module_file" in meta:
|
||||
module_file = meta["module_file"]
|
||||
else:
|
||||
index_file = "index.py"
|
||||
module_file = "main.py"
|
||||
|
||||
if "start_on_boot" in meta:
|
||||
enabled = meta["start_on_boot"]
|
||||
|
@ -139,7 +139,7 @@ class ModuleControlUnit:
|
|||
else:
|
||||
alias = None
|
||||
|
||||
self.modules.append(ModuleV2(f"modules/{folder}/", index_file, enabled, alias))
|
||||
self.modules.append(ModuleV2(f"modules/{folder}/", module_file, enabled, alias))
|
||||
|
||||
print(f"[INFO] reload_modules: successfully loaded {folder} as {alias} (start_on_boot: {enabled})")
|
||||
|
||||
|
|
|
@ -48,11 +48,12 @@ if self.MESSAGE["text"].lower() == "!пара":
|
|||
|
||||
print("test2")
|
||||
if next_lesson_time == None:
|
||||
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
||||
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||
|
||||
if len(full_schedule.keys()) > 0:
|
||||
print("test3.1")
|
||||
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
||||
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||
p = full_schedule[min(full_schedule.keys())]
|
||||
print("test3.1.1")
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "auto-schedule-pro",
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"predefine": "predefine.py"
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"start_on_boot": false
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"start_on_boot": true,
|
||||
"alias": "irc-bridge",
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"predefine": "predefine.py"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"predefine": "predefine.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "mass-tagger"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "qna-basic"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"version": 1,
|
||||
"index_file": "index.py",
|
||||
"version": 2,
|
||||
"index_file": "main.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "translit-decoder",
|
||||
"predefine": "predefine.py"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue