Reworking module naming conventions.
This commit is contained in:
parent
e4f0e88a58
commit
0f127d9efa
22
main.py
22
main.py
|
@ -57,13 +57,13 @@ class ModuleV1:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
class ModuleV2:
|
class ModuleV2:
|
||||||
def __init__(self, path, index_file, enabled, alias):
|
def __init__(self, path, module_file, enabled, alias):
|
||||||
self.version = 2
|
self.version = 2
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.alias = alias
|
self.alias = alias
|
||||||
self.path = path
|
self.path = path
|
||||||
self.index_file = index_file[:-3]
|
self.module_file = module_file[:-3]
|
||||||
self.obj = importlib.import_module((path + self.index_file).replace("/", "."))
|
self.obj = importlib.import_module((path + self.module_file).replace("/", "."))
|
||||||
|
|
||||||
# running the module
|
# running the module
|
||||||
def process(self, msg):
|
def process(self, msg):
|
||||||
|
@ -94,12 +94,12 @@ class ModuleControlUnit:
|
||||||
meta = json.loads( meta_raw )
|
meta = json.loads( meta_raw )
|
||||||
if "version" in meta:
|
if "version" in meta:
|
||||||
if meta["version"] == 1:
|
if meta["version"] == 1:
|
||||||
if "index_file" in meta:
|
if "module_file" in meta:
|
||||||
index_file = meta["index_file"]
|
module_file = meta["module_file"]
|
||||||
else:
|
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
|
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))
|
print("[WARN] reload_modules: module {} does not have any code, skipping...".format(folder))
|
||||||
continue
|
continue
|
||||||
|
@ -124,10 +124,10 @@ class ModuleControlUnit:
|
||||||
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))
|
||||||
|
|
||||||
elif meta["version"] == 2:
|
elif meta["version"] == 2:
|
||||||
if "index_file" in meta:
|
if "module_file" in meta:
|
||||||
index_file = meta["index_file"]
|
module_file = meta["module_file"]
|
||||||
else:
|
else:
|
||||||
index_file = "index.py"
|
module_file = "main.py"
|
||||||
|
|
||||||
if "start_on_boot" in meta:
|
if "start_on_boot" in meta:
|
||||||
enabled = meta["start_on_boot"]
|
enabled = meta["start_on_boot"]
|
||||||
|
@ -139,7 +139,7 @@ class ModuleControlUnit:
|
||||||
else:
|
else:
|
||||||
alias = None
|
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})")
|
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")
|
print("test2")
|
||||||
if next_lesson_time == None:
|
if next_lesson_time == None:
|
||||||
if len(full_schedule.keys()) > 0:
|
|
||||||
print("test3.1")
|
|
||||||
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
actual_lesson_ts = reference_time + min(full_schedule.keys())
|
||||||
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
dt_lesson = datetime.datetime.fromtimestamp(actual_lesson_ts)
|
||||||
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
dt_lesson_finish = datetime.datetime.fromtimestamp(actual_lesson_ts + 5400)
|
||||||
|
|
||||||
|
if len(full_schedule.keys()) > 0:
|
||||||
|
print("test3.1")
|
||||||
p = full_schedule[min(full_schedule.keys())]
|
p = full_schedule[min(full_schedule.keys())]
|
||||||
print("test3.1.1")
|
print("test3.1.1")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
|
"version": 2,
|
||||||
|
"index_file": "main.py",
|
||||||
"start_on_boot": true,
|
"start_on_boot": true,
|
||||||
"alias": "auto-schedule-pro",
|
"alias": "auto-schedule-pro",
|
||||||
"version": 1,
|
|
||||||
"index_file": "index.py",
|
|
||||||
"predefine": "predefine.py"
|
"predefine": "predefine.py"
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 2,
|
||||||
"index_file": "index.py",
|
"index_file": "main.py",
|
||||||
"start_on_boot": false
|
"start_on_boot": false
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"start_on_boot": true,
|
"start_on_boot": true,
|
||||||
"alias": "irc-bridge",
|
"alias": "irc-bridge",
|
||||||
"version": 1,
|
"version": 2,
|
||||||
"index_file": "index.py",
|
"index_file": "main.py",
|
||||||
"predefine": "predefine.py"
|
"predefine": "predefine.py"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 2,
|
||||||
"index_file": "index.py",
|
"index_file": "main.py",
|
||||||
"predefine": "predefine.py",
|
"predefine": "predefine.py",
|
||||||
"start_on_boot": true,
|
"start_on_boot": true,
|
||||||
"alias": "mass-tagger"
|
"alias": "mass-tagger"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 2,
|
||||||
"index_file": "index.py",
|
"index_file": "main.py",
|
||||||
"start_on_boot": true,
|
"start_on_boot": true,
|
||||||
"alias": "qna-basic"
|
"alias": "qna-basic"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": 1,
|
"version": 2,
|
||||||
"index_file": "index.py",
|
"index_file": "main.py",
|
||||||
"start_on_boot": true,
|
"start_on_boot": true,
|
||||||
"alias": "translit-decoder",
|
"alias": "translit-decoder",
|
||||||
"predefine": "predefine.py"
|
"predefine": "predefine.py"
|
||||||
|
|
Loading…
Reference in New Issue