ErisPulse 1.0.14.dev1__py3-none-any.whl → 1.0.14.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ErisPulse/__init__.py +7 -5
- ErisPulse/__main__.py +18 -17
- ErisPulse/db.py +9 -139
- ErisPulse/logger.py +29 -0
- ErisPulse/mods.py +86 -0
- {erispulse-1.0.14.dev1.dist-info → erispulse-1.0.14.dev3.dist-info}/METADATA +1 -1
- erispulse-1.0.14.dev3.dist-info/RECORD +12 -0
- erispulse-1.0.14.dev1.dist-info/RECORD +0 -11
- {erispulse-1.0.14.dev1.dist-info → erispulse-1.0.14.dev3.dist-info}/WHEEL +0 -0
- {erispulse-1.0.14.dev1.dist-info → erispulse-1.0.14.dev3.dist-info}/entry_points.txt +0 -0
- {erispulse-1.0.14.dev1.dist-info → erispulse-1.0.14.dev3.dist-info}/top_level.txt +0 -0
ErisPulse/__init__.py
CHANGED
|
@@ -5,6 +5,7 @@ from . import util
|
|
|
5
5
|
from .raiserr import raiserr
|
|
6
6
|
from .logger import logger
|
|
7
7
|
from .db import env
|
|
8
|
+
from .mods import mods
|
|
8
9
|
|
|
9
10
|
# 注册 ErrorHook 并预注册常用错误类型
|
|
10
11
|
raiserr.register("MissingDependencyError", doc="缺少依赖错误")
|
|
@@ -14,6 +15,7 @@ raiserr.register("ModuleLoadError" , doc="模块加载错误")
|
|
|
14
15
|
|
|
15
16
|
sdk = types.SimpleNamespace()
|
|
16
17
|
setattr(sdk, "env", env)
|
|
18
|
+
setattr(sdk, "mods", mods)
|
|
17
19
|
setattr(sdk, "raiserr", raiserr)
|
|
18
20
|
setattr(sdk, "logger", logger)
|
|
19
21
|
setattr(sdk, "util", util)
|
|
@@ -50,13 +52,13 @@ def init():
|
|
|
50
52
|
logger.warning(f"模块 {module_name} 缺少 'Main' 类.")
|
|
51
53
|
continue
|
|
52
54
|
|
|
53
|
-
module_info =
|
|
55
|
+
module_info = mods.get_module(moduleObj.moduleInfo.get("meta", {}).get("name", None))
|
|
54
56
|
if module_info is None:
|
|
55
57
|
module_info = {
|
|
56
58
|
"status": True,
|
|
57
59
|
"info": moduleObj.moduleInfo
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
mods.set_module(moduleObj.moduleInfo.get("meta", {}).get("name", None), module_info)
|
|
60
62
|
logger.info(f"模块 {moduleObj.moduleInfo.get('meta', {}).get('name', None)} 信息已初始化并存储到数据库")
|
|
61
63
|
|
|
62
64
|
if not module_info.get('status', True):
|
|
@@ -121,8 +123,8 @@ def init():
|
|
|
121
123
|
moduleObj = __import__(module_name)
|
|
122
124
|
moduleInfo: dict = moduleObj.moduleInfo
|
|
123
125
|
|
|
124
|
-
module_info =
|
|
125
|
-
|
|
126
|
+
module_info = mods.get_module(moduleInfo.get("meta", {}).get("name", None))
|
|
127
|
+
mods.set_module(moduleInfo.get("meta", {}).get("name", None), {
|
|
126
128
|
"status": True,
|
|
127
129
|
"info": moduleInfo
|
|
128
130
|
})
|
|
@@ -131,7 +133,7 @@ def init():
|
|
|
131
133
|
for module_name in sdkInstalledModuleNames:
|
|
132
134
|
moduleObj = __import__(module_name)
|
|
133
135
|
moduleInfo = moduleObj.moduleInfo
|
|
134
|
-
module_status =
|
|
136
|
+
module_status = mods.get_module_status(moduleInfo.get("meta", {}).get("name", None))
|
|
135
137
|
if not module_status:
|
|
136
138
|
continue
|
|
137
139
|
|
ErisPulse/__main__.py
CHANGED
|
@@ -9,6 +9,7 @@ import asyncio
|
|
|
9
9
|
import subprocess
|
|
10
10
|
import json
|
|
11
11
|
from .db import env
|
|
12
|
+
from .mods import mods
|
|
12
13
|
|
|
13
14
|
def print_panel(msg, title=None, border_style=None):
|
|
14
15
|
print("=" * 60)
|
|
@@ -157,17 +158,17 @@ class SourceManager:
|
|
|
157
158
|
print_panel(f"源 {value} 不存在", "错误")
|
|
158
159
|
|
|
159
160
|
def enable_module(module_name):
|
|
160
|
-
module_info =
|
|
161
|
+
module_info = mods.get_module(module_name)
|
|
161
162
|
if module_info:
|
|
162
|
-
|
|
163
|
+
mods.set_module_status(module_name, True)
|
|
163
164
|
print_panel(f"✓ 模块 {module_name} 已成功启用", "成功")
|
|
164
165
|
else:
|
|
165
166
|
print_panel(f"模块 {module_name} 不存在", "错误")
|
|
166
167
|
|
|
167
168
|
def disable_module(module_name):
|
|
168
|
-
module_info =
|
|
169
|
+
module_info = mods.get_module(module_name)
|
|
169
170
|
if module_info:
|
|
170
|
-
|
|
171
|
+
mods.set_module_status(module_name, False)
|
|
171
172
|
print_panel(f"✓ 模块 {module_name} 已成功禁用", "成功")
|
|
172
173
|
else:
|
|
173
174
|
print_panel(f"模块 {module_name} 不存在", "错误")
|
|
@@ -255,7 +256,7 @@ def install_module(module_name, force=False):
|
|
|
255
256
|
SourceManager().update_sources()
|
|
256
257
|
env.set('last_origin_update_time', datetime.now().isoformat())
|
|
257
258
|
print("✓ 源更新完成")
|
|
258
|
-
module_info =
|
|
259
|
+
module_info = mods.get_module(module_name)
|
|
259
260
|
if module_info and not force:
|
|
260
261
|
meta = module_info.get('info', {}).get('meta', {})
|
|
261
262
|
print_panel(
|
|
@@ -332,7 +333,7 @@ def install_module(module_name, force=False):
|
|
|
332
333
|
module_dir=module_dir
|
|
333
334
|
):
|
|
334
335
|
return
|
|
335
|
-
|
|
336
|
+
mods.set_module(module_name, {
|
|
336
337
|
'status': True,
|
|
337
338
|
'info': {
|
|
338
339
|
'meta': {
|
|
@@ -352,7 +353,7 @@ def install_module(module_name, force=False):
|
|
|
352
353
|
|
|
353
354
|
def uninstall_module(module_name):
|
|
354
355
|
print_panel(f"准备卸载模块: {module_name}", "卸载摘要")
|
|
355
|
-
module_info =
|
|
356
|
+
module_info = mods.get_module(module_name)
|
|
356
357
|
if not module_info:
|
|
357
358
|
print_panel(f"模块 {module_name} 不存在", "错误")
|
|
358
359
|
return
|
|
@@ -383,7 +384,7 @@ def uninstall_module(module_name):
|
|
|
383
384
|
return
|
|
384
385
|
pip_dependencies = depsinfo.get('pip', [])
|
|
385
386
|
if pip_dependencies:
|
|
386
|
-
all_modules =
|
|
387
|
+
all_modules = mods.get_all_modules()
|
|
387
388
|
unused_pip_dependencies = []
|
|
388
389
|
essential_packages = {'aiohttp'}
|
|
389
390
|
for dep in pip_dependencies:
|
|
@@ -419,13 +420,13 @@ def uninstall_module(module_name):
|
|
|
419
420
|
f"卸载 pip 依赖失败: {e.stderr.decode()}",
|
|
420
421
|
"错误"
|
|
421
422
|
)
|
|
422
|
-
if
|
|
423
|
+
if mods.remove_module(module_name):
|
|
423
424
|
print_panel(f"✓ 模块 {module_name} 已成功卸载", "成功")
|
|
424
425
|
else:
|
|
425
426
|
print_panel(f"模块 {module_name} 不存在", "错误")
|
|
426
427
|
|
|
427
428
|
def upgrade_all_modules(force=False):
|
|
428
|
-
all_modules =
|
|
429
|
+
all_modules = mods.get_all_modules()
|
|
429
430
|
if not all_modules:
|
|
430
431
|
print("未找到任何模块,无法更新")
|
|
431
432
|
return
|
|
@@ -478,16 +479,16 @@ def upgrade_all_modules(force=False):
|
|
|
478
479
|
):
|
|
479
480
|
continue
|
|
480
481
|
all_modules[update['name']]['info']['version'] = update['remote_version']
|
|
481
|
-
|
|
482
|
+
mods.set_all_modules(all_modules)
|
|
482
483
|
print(f"模块 {update['name']} 已更新至版本 {update['remote_version']}")
|
|
483
484
|
|
|
484
485
|
def list_modules(module_name=None):
|
|
485
|
-
all_modules =
|
|
486
|
+
all_modules = mods.get_all_modules()
|
|
486
487
|
if not all_modules:
|
|
487
488
|
print_panel("未在数据库中发现注册模块,正在初始化模块列表...", "提示")
|
|
488
489
|
from . import init as init_module
|
|
489
490
|
init_module()
|
|
490
|
-
all_modules =
|
|
491
|
+
all_modules = mods.get_all_modules()
|
|
491
492
|
if not all_modules:
|
|
492
493
|
print_panel("未找到任何模块", "错误")
|
|
493
494
|
return
|
|
@@ -576,7 +577,7 @@ def main():
|
|
|
576
577
|
continue
|
|
577
578
|
if '*' in module_name or '?' in module_name:
|
|
578
579
|
print(f"正在匹配模块模式: {module_name}...")
|
|
579
|
-
all_modules =
|
|
580
|
+
all_modules = mods.get_all_modules()
|
|
580
581
|
if not all_modules:
|
|
581
582
|
print_panel("未找到任何模块,请先更新源或检查配置", "错误")
|
|
582
583
|
continue
|
|
@@ -601,7 +602,7 @@ def main():
|
|
|
601
602
|
continue
|
|
602
603
|
if '*' in module_name or '?' in module_name:
|
|
603
604
|
print(f"正在匹配模块模式: {module_name}...")
|
|
604
|
-
all_modules =
|
|
605
|
+
all_modules = mods.get_all_modules()
|
|
605
606
|
if not all_modules:
|
|
606
607
|
print_panel("未找到任何模块,请先更新源或检查配置", "错误")
|
|
607
608
|
continue
|
|
@@ -628,7 +629,7 @@ def main():
|
|
|
628
629
|
continue
|
|
629
630
|
if '*' in module_name or '?' in module_name:
|
|
630
631
|
print(f"正在匹配模块模式: {module_name}...")
|
|
631
|
-
all_modules =
|
|
632
|
+
all_modules = mods.get_all_modules()
|
|
632
633
|
if not all_modules:
|
|
633
634
|
print_panel("未找到任何模块,请先更新源或检查配置", "错误")
|
|
634
635
|
continue
|
|
@@ -653,7 +654,7 @@ def main():
|
|
|
653
654
|
continue
|
|
654
655
|
if '*' in module_name or '?' in module_name:
|
|
655
656
|
print(f"正在匹配模块模式: {module_name}...")
|
|
656
|
-
all_modules =
|
|
657
|
+
all_modules = mods.get_all_modules()
|
|
657
658
|
if not all_modules:
|
|
658
659
|
print_panel("未找到任何模块,请先更新源或检查配置", "错误")
|
|
659
660
|
continue
|
ErisPulse/db.py
CHANGED
|
@@ -11,17 +11,15 @@ class EnvManager:
|
|
|
11
11
|
def __new__(cls, *args, **kwargs):
|
|
12
12
|
if not cls._instance:
|
|
13
13
|
cls._instance = super().__new__(cls)
|
|
14
|
-
cls._instance.dev_mode = kwargs.get('dev_mode', False)
|
|
15
14
|
return cls._instance
|
|
16
15
|
|
|
17
|
-
def __init__(self
|
|
16
|
+
def __init__(self):
|
|
18
17
|
if not hasattr(self, "_initialized"):
|
|
19
|
-
self.dev_mode = dev_mode
|
|
20
18
|
self._init_db()
|
|
19
|
+
self._initialized = True
|
|
21
20
|
|
|
22
21
|
def _init_db(self):
|
|
23
22
|
os.makedirs(os.path.dirname(self.db_path), exist_ok=True)
|
|
24
|
-
|
|
25
23
|
conn = sqlite3.connect(self.db_path)
|
|
26
24
|
cursor = conn.cursor()
|
|
27
25
|
cursor.execute("""
|
|
@@ -30,18 +28,6 @@ class EnvManager:
|
|
|
30
28
|
value TEXT NOT NULL
|
|
31
29
|
)
|
|
32
30
|
""")
|
|
33
|
-
cursor.execute("""
|
|
34
|
-
CREATE TABLE IF NOT EXISTS modules (
|
|
35
|
-
module_name TEXT PRIMARY KEY,
|
|
36
|
-
status INTEGER NOT NULL,
|
|
37
|
-
version TEXT,
|
|
38
|
-
description TEXT,
|
|
39
|
-
author TEXT,
|
|
40
|
-
dependencies TEXT,
|
|
41
|
-
optional_dependencies TEXT,
|
|
42
|
-
pip_dependencies TEXT
|
|
43
|
-
)
|
|
44
|
-
""")
|
|
45
31
|
conn.commit()
|
|
46
32
|
conn.close()
|
|
47
33
|
|
|
@@ -63,7 +49,13 @@ class EnvManager:
|
|
|
63
49
|
return self.get(key, default)
|
|
64
50
|
else:
|
|
65
51
|
raise
|
|
66
|
-
|
|
52
|
+
|
|
53
|
+
def get_all_keys(self) -> list:
|
|
54
|
+
with sqlite3.connect(self.db_path) as conn:
|
|
55
|
+
cursor = conn.cursor()
|
|
56
|
+
cursor.execute("SELECT key FROM config")
|
|
57
|
+
return [row[0] for row in cursor.fetchall()]
|
|
58
|
+
|
|
67
59
|
def set(self, key, value):
|
|
68
60
|
serialized_value = json.dumps(value) if isinstance(value, (dict, list)) else str(value)
|
|
69
61
|
conn = sqlite3.connect(self.db_path)
|
|
@@ -95,128 +87,6 @@ class EnvManager:
|
|
|
95
87
|
for key, value in vars(env_module).items():
|
|
96
88
|
if not key.startswith("__") and isinstance(value, (dict, list, str, int, float, bool)):
|
|
97
89
|
self.set(key, value)
|
|
98
|
-
def set_module_status(self, module_name, status):
|
|
99
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
100
|
-
cursor = conn.cursor()
|
|
101
|
-
cursor.execute("""
|
|
102
|
-
UPDATE modules SET status = ? WHERE module_name = ?
|
|
103
|
-
""", (int(status), module_name))
|
|
104
|
-
conn.commit()
|
|
105
|
-
|
|
106
|
-
def get_module_status(self, module_name):
|
|
107
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
108
|
-
cursor = conn.cursor()
|
|
109
|
-
cursor.execute("""
|
|
110
|
-
SELECT status FROM modules WHERE module_name = ?
|
|
111
|
-
""", (module_name,))
|
|
112
|
-
result = cursor.fetchone()
|
|
113
|
-
return bool(result[0]) if result else True
|
|
114
|
-
|
|
115
|
-
def set_all_modules(self, modules_info):
|
|
116
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
117
|
-
cursor = conn.cursor()
|
|
118
|
-
for module_name, module_info in modules_info.items():
|
|
119
|
-
meta = module_info.get('info', {}).get('meta', {})
|
|
120
|
-
dependencies = module_info.get('info', {}).get('dependencies', {})
|
|
121
|
-
cursor.execute("""
|
|
122
|
-
INSERT OR REPLACE INTO modules (
|
|
123
|
-
module_name, status, version, description, author,
|
|
124
|
-
dependencies, optional_dependencies, pip_dependencies
|
|
125
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
126
|
-
""", (
|
|
127
|
-
module_name,
|
|
128
|
-
int(module_info.get('status', True)),
|
|
129
|
-
meta.get('version', ''),
|
|
130
|
-
meta.get('description', ''),
|
|
131
|
-
meta.get('author', ''),
|
|
132
|
-
json.dumps(dependencies.get('requires', [])),
|
|
133
|
-
json.dumps(dependencies.get('optional', [])),
|
|
134
|
-
json.dumps(dependencies.get('pip', []))
|
|
135
|
-
))
|
|
136
|
-
conn.commit()
|
|
137
|
-
|
|
138
|
-
def get_all_modules(self):
|
|
139
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
140
|
-
cursor = conn.cursor()
|
|
141
|
-
cursor.execute("SELECT * FROM modules")
|
|
142
|
-
rows = cursor.fetchall()
|
|
143
|
-
modules_info = {}
|
|
144
|
-
for row in rows:
|
|
145
|
-
module_name, status, version, description, author, dependencies, optional_dependencies, pip_dependencies = row
|
|
146
|
-
modules_info[module_name] = {
|
|
147
|
-
'status': bool(status),
|
|
148
|
-
'info': {
|
|
149
|
-
'meta': {
|
|
150
|
-
'version': version,
|
|
151
|
-
'description': description,
|
|
152
|
-
'author': author,
|
|
153
|
-
'pip_dependencies': json.loads(pip_dependencies) if pip_dependencies else []
|
|
154
|
-
},
|
|
155
|
-
'dependencies': {
|
|
156
|
-
'requires': json.loads(dependencies) if dependencies else [],
|
|
157
|
-
'optional': json.loads(optional_dependencies) if optional_dependencies else [],
|
|
158
|
-
'pip': json.loads(pip_dependencies) if pip_dependencies else []
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return modules_info
|
|
163
|
-
|
|
164
|
-
def set_module(self, module_name, module_info):
|
|
165
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
166
|
-
cursor = conn.cursor()
|
|
167
|
-
meta = module_info.get('info', {}).get('meta', {})
|
|
168
|
-
dependencies = module_info.get('info', {}).get('dependencies', {})
|
|
169
|
-
cursor.execute("""
|
|
170
|
-
INSERT OR REPLACE INTO modules (
|
|
171
|
-
module_name, status, version, description, author,
|
|
172
|
-
dependencies, optional_dependencies, pip_dependencies
|
|
173
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
174
|
-
""", (
|
|
175
|
-
module_name,
|
|
176
|
-
int(module_info.get('status', True)),
|
|
177
|
-
meta.get('version', ''),
|
|
178
|
-
meta.get('description', ''),
|
|
179
|
-
meta.get('author', ''),
|
|
180
|
-
json.dumps(dependencies.get('requires', [])),
|
|
181
|
-
json.dumps(dependencies.get('optional', [])),
|
|
182
|
-
json.dumps(dependencies.get('pip', []))
|
|
183
|
-
))
|
|
184
|
-
conn.commit()
|
|
185
|
-
|
|
186
|
-
def get_module(self, module_name):
|
|
187
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
188
|
-
cursor = conn.cursor()
|
|
189
|
-
cursor.execute("SELECT * FROM modules WHERE module_name = ?", (module_name,))
|
|
190
|
-
row = cursor.fetchone()
|
|
191
|
-
if row:
|
|
192
|
-
module_name, status, version, description, author, dependencies, optional_dependencies, pip_dependencies = row
|
|
193
|
-
return {
|
|
194
|
-
'status': bool(status),
|
|
195
|
-
'info': {
|
|
196
|
-
'meta': {
|
|
197
|
-
'version': version,
|
|
198
|
-
'description': description,
|
|
199
|
-
'author': author,
|
|
200
|
-
'pip_dependencies': json.loads(pip_dependencies) if pip_dependencies else []
|
|
201
|
-
},
|
|
202
|
-
'dependencies': {
|
|
203
|
-
'requires': json.loads(dependencies) if dependencies else [],
|
|
204
|
-
'optional': json.loads(optional_dependencies) if optional_dependencies else [],
|
|
205
|
-
'pip': json.loads(pip_dependencies) if pip_dependencies else []
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return None
|
|
210
|
-
|
|
211
|
-
def update_module(self, module_name, module_info):
|
|
212
|
-
self.set_module(module_name, module_info)
|
|
213
|
-
|
|
214
|
-
def remove_module(self, module_name):
|
|
215
|
-
with sqlite3.connect(self.db_path) as conn:
|
|
216
|
-
cursor = conn.cursor()
|
|
217
|
-
cursor.execute("DELETE FROM modules WHERE module_name = ?", (module_name,))
|
|
218
|
-
conn.commit()
|
|
219
|
-
return cursor.rowcount > 0
|
|
220
90
|
|
|
221
91
|
def __getattr__(self, key):
|
|
222
92
|
try:
|
ErisPulse/logger.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import inspect
|
|
3
3
|
import datetime
|
|
4
|
+
import functools
|
|
4
5
|
|
|
5
6
|
class Logger:
|
|
6
7
|
def __init__(self):
|
|
@@ -69,6 +70,34 @@ class Logger:
|
|
|
69
70
|
except Exception as e:
|
|
70
71
|
self._logger.error(f"无法保存日志到 {p}: {e}。")
|
|
71
72
|
raise e
|
|
73
|
+
|
|
74
|
+
def catch(self, func_or_level=None, level="error"):
|
|
75
|
+
if isinstance(func_or_level, str):
|
|
76
|
+
return lambda func: self.catch(func, level=func_or_level)
|
|
77
|
+
if func_or_level is None:
|
|
78
|
+
return lambda func: self.catch(func, level=level)
|
|
79
|
+
func = func_or_level
|
|
80
|
+
|
|
81
|
+
@functools.wraps(func)
|
|
82
|
+
def wrapper(*args, **kwargs):
|
|
83
|
+
try:
|
|
84
|
+
return func(*args, **kwargs)
|
|
85
|
+
except Exception as e:
|
|
86
|
+
import traceback
|
|
87
|
+
error_info = traceback.format_exc()
|
|
88
|
+
|
|
89
|
+
module_name = func.__module__
|
|
90
|
+
if module_name == "__main__":
|
|
91
|
+
module_name = "Main"
|
|
92
|
+
func_name = func.__name__
|
|
93
|
+
|
|
94
|
+
error_msg = f"Exception in {func_name}: {str(e)}\n{error_info}"
|
|
95
|
+
|
|
96
|
+
log_method = getattr(self, level, self.error)
|
|
97
|
+
log_method(error_msg)
|
|
98
|
+
|
|
99
|
+
return None
|
|
100
|
+
return wrapper
|
|
72
101
|
|
|
73
102
|
def _save_in_memory(self, ModuleName, msg):
|
|
74
103
|
if ModuleName not in self._logs:
|
ErisPulse/mods.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Dict, Optional
|
|
3
|
+
|
|
4
|
+
class ModuleManager:
|
|
5
|
+
DEFAULT_MODULE_PREFIX = "erispulse.module.data:"
|
|
6
|
+
DEFAULT_STATUS_PREFIX = "erispulse.module.status:"
|
|
7
|
+
|
|
8
|
+
def __init__(self):
|
|
9
|
+
from .db import env
|
|
10
|
+
self.env = env
|
|
11
|
+
self._ensure_prefixes()
|
|
12
|
+
|
|
13
|
+
def _ensure_prefixes(self):
|
|
14
|
+
if not self.env.get("erispulse.system.module_prefix"):
|
|
15
|
+
self.env.set("erispulse.system.module_prefix", self.DEFAULT_MODULE_PREFIX)
|
|
16
|
+
if not self.env.get("erispulse.system.status_prefix"):
|
|
17
|
+
self.env.set("erispulse.system.status_prefix", self.DEFAULT_STATUS_PREFIX)
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def module_prefix(self) -> str:
|
|
21
|
+
return self.env.get("erispulse.system.module_prefix")
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def status_prefix(self) -> str:
|
|
25
|
+
return self.env.get("erispulse.system.status_prefix")
|
|
26
|
+
|
|
27
|
+
def set_module_status(self, module_name: str, status: bool) -> None:
|
|
28
|
+
self.env.set(f"{self.status_prefix}{module_name}", bool(status))
|
|
29
|
+
|
|
30
|
+
def get_module_status(self, module_name: str) -> bool:
|
|
31
|
+
status = self.env.get(f"{self.status_prefix}{module_name}", True)
|
|
32
|
+
if isinstance(status, str):
|
|
33
|
+
return status.lower() == 'true'
|
|
34
|
+
return bool(status)
|
|
35
|
+
|
|
36
|
+
def set_module(self, module_name: str, module_info: dict) -> None:
|
|
37
|
+
self.env.set(f"{self.module_prefix}{module_name}", module_info)
|
|
38
|
+
self.set_module_status(module_name, module_info.get('status', True))
|
|
39
|
+
|
|
40
|
+
def get_module(self, module_name: str) -> Optional[dict]:
|
|
41
|
+
return self.env.get(f"{self.module_prefix}{module_name}")
|
|
42
|
+
|
|
43
|
+
def set_all_modules(self, modules_info: Dict[str, dict]) -> None:
|
|
44
|
+
for module_name, module_info in modules_info.items():
|
|
45
|
+
self.set_module(module_name, module_info)
|
|
46
|
+
|
|
47
|
+
def get_all_modules(self) -> dict:
|
|
48
|
+
modules_info = {}
|
|
49
|
+
all_keys = self.env.get_all_keys()
|
|
50
|
+
prefix_len = len(self.module_prefix)
|
|
51
|
+
|
|
52
|
+
for key in all_keys:
|
|
53
|
+
if key.startswith(self.module_prefix):
|
|
54
|
+
module_name = key[prefix_len:]
|
|
55
|
+
module_info = self.get_module(module_name)
|
|
56
|
+
if module_info:
|
|
57
|
+
status = self.get_module_status(module_name)
|
|
58
|
+
module_info['status'] = bool(status)
|
|
59
|
+
modules_info[module_name] = module_info
|
|
60
|
+
return modules_info
|
|
61
|
+
|
|
62
|
+
def update_module(self, module_name: str, module_info: dict) -> None:
|
|
63
|
+
self.set_module(module_name, module_info)
|
|
64
|
+
|
|
65
|
+
def remove_module(self, module_name: str) -> bool:
|
|
66
|
+
module_key = f"{self.module_prefix}{module_name}"
|
|
67
|
+
status_key = f"{self.status_prefix}{module_name}"
|
|
68
|
+
|
|
69
|
+
if self.env.get(module_key) is not None:
|
|
70
|
+
self.env.delete(module_key)
|
|
71
|
+
self.env.delete(status_key)
|
|
72
|
+
return True
|
|
73
|
+
return False
|
|
74
|
+
|
|
75
|
+
def update_prefixes(self, module_prefix: str = None, status_prefix: str = None) -> None:
|
|
76
|
+
if module_prefix:
|
|
77
|
+
if not module_prefix.endswith(':'):
|
|
78
|
+
module_prefix += ':'
|
|
79
|
+
self.env.set("erispulse.system.module_prefix", module_prefix)
|
|
80
|
+
|
|
81
|
+
if status_prefix:
|
|
82
|
+
if not status_prefix.endswith(':'):
|
|
83
|
+
status_prefix += ':'
|
|
84
|
+
self.env.set("erispulse.system.status_prefix", status_prefix)
|
|
85
|
+
|
|
86
|
+
mods = ModuleManager()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ErisPulse
|
|
3
|
-
Version: 1.0.14.
|
|
3
|
+
Version: 1.0.14.dev3
|
|
4
4
|
Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
|
|
5
5
|
Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
|
|
6
6
|
Classifier: Development Status :: 5 - Production/Stable
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
ErisPulse/__init__.py,sha256=eLYg5fmwxwXsH7YK7z2f5AZRZA5SQIoS0xqMJN7KhVg,6717
|
|
2
|
+
ErisPulse/__main__.py,sha256=-UdhsYP_X7EagomCjo73Y_qQdXwtMbDS5KoOSrI-OcU,32181
|
|
3
|
+
ErisPulse/db.py,sha256=CnREeykvRmEDx9HE4bS4gakcAUYWuBOfN3WgPsQMAd4,3208
|
|
4
|
+
ErisPulse/logger.py,sha256=HwceD81nLiLCh_WGcCVsEG6OqL-NL5HmdONFTGH-8Og,6023
|
|
5
|
+
ErisPulse/mods.py,sha256=o6yT5YhNyfeCpXrEFZYSBCr3YQqjFXZ0hN3u1XoKHJ4,3360
|
|
6
|
+
ErisPulse/raiserr.py,sha256=WTMQEUbUSx4PS9_l9cEnuNuvm6zulgwQFipqVZZg3zc,1296
|
|
7
|
+
ErisPulse/util.py,sha256=90j71c32yP-s2zy1SM-1FExJRu7pWpkuPVQSXCaVTrg,1087
|
|
8
|
+
erispulse-1.0.14.dev3.dist-info/METADATA,sha256=ALV5xc2zQl_1ZcDNM3yjGKCOAbM1o3J5RaXqg0N5DVg,2502
|
|
9
|
+
erispulse-1.0.14.dev3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
erispulse-1.0.14.dev3.dist-info/entry_points.txt,sha256=AjKvOdYR7QGXVpEJhjUYUwV2JluE4lm9vNbknC3hjOM,155
|
|
11
|
+
erispulse-1.0.14.dev3.dist-info/top_level.txt,sha256=Lm_qtkVvNJR8_dXh_qEDdl_12cZGpic-i4HUlVVUMZc,10
|
|
12
|
+
erispulse-1.0.14.dev3.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
ErisPulse/__init__.py,sha256=75SfkJEYHy73K3UGaEuMYlHtJadjpoNWd1yF-f5-aGc,6662
|
|
2
|
-
ErisPulse/__main__.py,sha256=1-mWPmZArG-o_eYxZiabmMs4MokQn_-TBa43R4_WYlc,32141
|
|
3
|
-
ErisPulse/db.py,sha256=2vBVFFEU-AcR-GkzWTqpn8fFV9EvuQee2mi1XzfDXVI,9077
|
|
4
|
-
ErisPulse/logger.py,sha256=AVjBuoF18Wu6mPMxB90i7Nge0IoMx2xPlTYrQX-UKaU,4973
|
|
5
|
-
ErisPulse/raiserr.py,sha256=WTMQEUbUSx4PS9_l9cEnuNuvm6zulgwQFipqVZZg3zc,1296
|
|
6
|
-
ErisPulse/util.py,sha256=90j71c32yP-s2zy1SM-1FExJRu7pWpkuPVQSXCaVTrg,1087
|
|
7
|
-
erispulse-1.0.14.dev1.dist-info/METADATA,sha256=132PK2kNWhBPBoQdx-9yf6wJV7RNQpksk3EjwMdAjOc,2502
|
|
8
|
-
erispulse-1.0.14.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
erispulse-1.0.14.dev1.dist-info/entry_points.txt,sha256=AjKvOdYR7QGXVpEJhjUYUwV2JluE4lm9vNbknC3hjOM,155
|
|
10
|
-
erispulse-1.0.14.dev1.dist-info/top_level.txt,sha256=Lm_qtkVvNJR8_dXh_qEDdl_12cZGpic-i4HUlVVUMZc,10
|
|
11
|
-
erispulse-1.0.14.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|