ErisPulse 2.1.8__py3-none-any.whl → 2.1.10__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/Core/__init__.py +0 -36
- ErisPulse/Core/adapter.py +3 -6
- ErisPulse/Core/config.py +172 -0
- ErisPulse/Core/env.py +5 -33
- ErisPulse/Core/logger.py +9 -12
- {erispulse-2.1.8.dist-info → erispulse-2.1.10.dist-info}/METADATA +1 -1
- erispulse-2.1.10.dist-info/RECORD +16 -0
- erispulse-2.1.8.dist-info/RECORD +0 -15
- {erispulse-2.1.8.dist-info → erispulse-2.1.10.dist-info}/WHEEL +0 -0
- {erispulse-2.1.8.dist-info → erispulse-2.1.10.dist-info}/entry_points.txt +0 -0
- {erispulse-2.1.8.dist-info → erispulse-2.1.10.dist-info}/licenses/LICENSE +0 -0
ErisPulse/Core/__init__.py
CHANGED
|
@@ -19,39 +19,3 @@ __all__ = [
|
|
|
19
19
|
'util',
|
|
20
20
|
'adapter_server'
|
|
21
21
|
]
|
|
22
|
-
|
|
23
|
-
_config = env.getConfig("ErisPulse")
|
|
24
|
-
|
|
25
|
-
if _config is None:
|
|
26
|
-
defaultConfig = {
|
|
27
|
-
"server": {
|
|
28
|
-
"host": "0.0.0.0",
|
|
29
|
-
"port": 8000,
|
|
30
|
-
"ssl_certfile": None,
|
|
31
|
-
"ssl_keyfile": None
|
|
32
|
-
},
|
|
33
|
-
"logger": {
|
|
34
|
-
"level": "INFO",
|
|
35
|
-
"log_files": [],
|
|
36
|
-
"memory_limit": 1000
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
env.setConfig("ErisPulse", defaultConfig)
|
|
40
|
-
_config = defaultConfig
|
|
41
|
-
|
|
42
|
-
if _config.get("server") is None:
|
|
43
|
-
_config["server"] = {
|
|
44
|
-
"host": "0.0.0.0",
|
|
45
|
-
"port": 8000,
|
|
46
|
-
"ssl_certfile": None,
|
|
47
|
-
"ssl_keyfile": None
|
|
48
|
-
}
|
|
49
|
-
env.setConfig("ErisPulse", _config)
|
|
50
|
-
|
|
51
|
-
if _config.get("logger") is None:
|
|
52
|
-
_config["logger"] = {
|
|
53
|
-
"level": "INFO",
|
|
54
|
-
"log_files": [],
|
|
55
|
-
"memory_limit": 1000
|
|
56
|
-
}
|
|
57
|
-
env.setConfig("ErisPulse", _config)
|
ErisPulse/Core/adapter.py
CHANGED
|
@@ -402,17 +402,14 @@ class AdapterManager:
|
|
|
402
402
|
if platforms is None:
|
|
403
403
|
platforms = list(self._adapters.keys())
|
|
404
404
|
|
|
405
|
-
from .env import env
|
|
406
|
-
from .logger import logger
|
|
407
405
|
from .server import adapter_server
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
server_config = _config.get("server", {})
|
|
406
|
+
from .config import get_server_config
|
|
407
|
+
server_config = get_server_config()
|
|
411
408
|
host = server_config["host"]
|
|
412
409
|
port = server_config["port"]
|
|
413
410
|
ssl_cert = server_config.get("ssl_certfile", None)
|
|
414
411
|
ssl_key = server_config.get("ssl_keyfile", None)
|
|
415
|
-
|
|
412
|
+
|
|
416
413
|
# 启动服务器
|
|
417
414
|
await adapter_server.start(
|
|
418
415
|
host=host,
|
ErisPulse/Core/config.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ErisPulse 配置中心
|
|
3
|
+
|
|
4
|
+
集中管理所有配置项,避免循环导入问题
|
|
5
|
+
提供自动补全缺失配置项的功能
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import toml
|
|
9
|
+
from typing import Dict, Any, Optional
|
|
10
|
+
|
|
11
|
+
class ConfigManager:
|
|
12
|
+
def __init__(self, config_file: str = "config.toml"):
|
|
13
|
+
self.CONFIG_FILE = config_file
|
|
14
|
+
|
|
15
|
+
def getConfig(self, key: str, default: Any = None) -> Any:
|
|
16
|
+
"""
|
|
17
|
+
获取模块/适配器配置项
|
|
18
|
+
:param key: 配置项的键(支持点分隔符如"module.sub.key")
|
|
19
|
+
:param default: 默认值
|
|
20
|
+
:return: 配置项的值
|
|
21
|
+
"""
|
|
22
|
+
try:
|
|
23
|
+
if not os.path.exists(self.CONFIG_FILE):
|
|
24
|
+
return default
|
|
25
|
+
|
|
26
|
+
with open(self.CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
27
|
+
config = toml.load(f)
|
|
28
|
+
|
|
29
|
+
# 支持点分隔符访问嵌套配置
|
|
30
|
+
keys = key.split('.')
|
|
31
|
+
value = config
|
|
32
|
+
for k in keys:
|
|
33
|
+
if k not in value:
|
|
34
|
+
return default
|
|
35
|
+
value = value[k]
|
|
36
|
+
|
|
37
|
+
return value
|
|
38
|
+
except Exception as e:
|
|
39
|
+
from . import logger
|
|
40
|
+
logger.error(f"读取配置文件 {self.CONFIG_FILE} 失败: {e}")
|
|
41
|
+
return default
|
|
42
|
+
|
|
43
|
+
def setConfig(self, key: str, value: Any) -> bool:
|
|
44
|
+
"""
|
|
45
|
+
设置模块/适配器配置
|
|
46
|
+
:param key: 配置项键名(支持点分隔符如"module.sub.key")
|
|
47
|
+
:param value: 配置项值
|
|
48
|
+
:return: 操作是否成功
|
|
49
|
+
"""
|
|
50
|
+
try:
|
|
51
|
+
config = {}
|
|
52
|
+
if os.path.exists(self.CONFIG_FILE):
|
|
53
|
+
with open(self.CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
54
|
+
config = toml.load(f)
|
|
55
|
+
|
|
56
|
+
# 支持点分隔符设置嵌套配置
|
|
57
|
+
keys = key.split('.')
|
|
58
|
+
current = config
|
|
59
|
+
for k in keys[:-1]:
|
|
60
|
+
if k not in current:
|
|
61
|
+
current[k] = {}
|
|
62
|
+
current = current[k]
|
|
63
|
+
current[keys[-1]] = value
|
|
64
|
+
|
|
65
|
+
with open(self.CONFIG_FILE, "w", encoding="utf-8") as f:
|
|
66
|
+
toml.dump(config, f)
|
|
67
|
+
|
|
68
|
+
return True
|
|
69
|
+
except Exception as e:
|
|
70
|
+
from . import logger
|
|
71
|
+
logger.error(f"写入配置文件 {self.CONFIG_FILE} 失败: {e}")
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
config = ConfigManager()
|
|
75
|
+
|
|
76
|
+
# 默认配置
|
|
77
|
+
DEFAULT_CONFIG = {
|
|
78
|
+
"server": {
|
|
79
|
+
"host": "0.0.0.0",
|
|
80
|
+
"port": 8000,
|
|
81
|
+
"ssl_certfile": None,
|
|
82
|
+
"ssl_keyfile": None
|
|
83
|
+
},
|
|
84
|
+
"logger": {
|
|
85
|
+
"level": "INFO",
|
|
86
|
+
"log_files": [],
|
|
87
|
+
"memory_limit": 1000
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
def _ensure_config_structure(config: Dict[str, Any]) -> Dict[str, Any]:
|
|
92
|
+
"""
|
|
93
|
+
确保配置结构完整,补全缺失的配置项
|
|
94
|
+
|
|
95
|
+
:param config: 当前配置
|
|
96
|
+
:return: 补全后的完整配置
|
|
97
|
+
"""
|
|
98
|
+
merged_config = DEFAULT_CONFIG.copy()
|
|
99
|
+
|
|
100
|
+
# 深度合并配置
|
|
101
|
+
for section, default_values in DEFAULT_CONFIG.items():
|
|
102
|
+
if section not in config:
|
|
103
|
+
config[section] = default_values.copy()
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
if not isinstance(config[section], dict):
|
|
107
|
+
config[section] = default_values.copy()
|
|
108
|
+
continue
|
|
109
|
+
|
|
110
|
+
for key, default_value in default_values.items():
|
|
111
|
+
if key not in config[section]:
|
|
112
|
+
config[section][key] = default_value
|
|
113
|
+
|
|
114
|
+
return config
|
|
115
|
+
|
|
116
|
+
def get_config() -> Dict[str, Any]:
|
|
117
|
+
"""
|
|
118
|
+
获取当前配置,自动补全缺失的配置项并保存
|
|
119
|
+
|
|
120
|
+
:return: 完整的配置字典
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
# 获取现有配置
|
|
124
|
+
current_config = config.getConfig("ErisPulse")
|
|
125
|
+
|
|
126
|
+
# 如果完全没有配置,设置默认配置
|
|
127
|
+
if current_config is None:
|
|
128
|
+
config.setConfig("ErisPulse", DEFAULT_CONFIG)
|
|
129
|
+
return DEFAULT_CONFIG
|
|
130
|
+
|
|
131
|
+
# 检查并补全缺失的配置项
|
|
132
|
+
complete_config = _ensure_config_structure(current_config)
|
|
133
|
+
|
|
134
|
+
# 如果配置有变化,更新到存储
|
|
135
|
+
if current_config != complete_config:
|
|
136
|
+
config.setConfig("ErisPulse", complete_config)
|
|
137
|
+
|
|
138
|
+
return complete_config
|
|
139
|
+
|
|
140
|
+
def update_config(new_config: Dict[str, Any]) -> bool:
|
|
141
|
+
"""
|
|
142
|
+
更新配置,自动补全缺失的配置项
|
|
143
|
+
|
|
144
|
+
:param new_config: 新的配置字典
|
|
145
|
+
:return: 是否更新成功
|
|
146
|
+
"""
|
|
147
|
+
# 获取当前配置并合并新配置
|
|
148
|
+
current = get_config()
|
|
149
|
+
merged = {**current, **new_config}
|
|
150
|
+
|
|
151
|
+
# 确保合并后的配置结构完整
|
|
152
|
+
complete_config = _ensure_config_structure(merged)
|
|
153
|
+
|
|
154
|
+
return config.setConfig("ErisPulse", complete_config)
|
|
155
|
+
|
|
156
|
+
def get_server_config() -> Dict[str, Any]:
|
|
157
|
+
"""
|
|
158
|
+
获取服务器配置,确保结构完整
|
|
159
|
+
|
|
160
|
+
:return: 服务器配置字典
|
|
161
|
+
"""
|
|
162
|
+
config = get_config()
|
|
163
|
+
return config["server"]
|
|
164
|
+
|
|
165
|
+
def get_logger_config() -> Dict[str, Any]:
|
|
166
|
+
"""
|
|
167
|
+
获取日志配置,确保结构完整
|
|
168
|
+
|
|
169
|
+
:return: 日志配置字典
|
|
170
|
+
"""
|
|
171
|
+
config = get_config()
|
|
172
|
+
return config["logger"]
|
ErisPulse/Core/env.py
CHANGED
|
@@ -180,6 +180,7 @@ class EnvManager:
|
|
|
180
180
|
return True
|
|
181
181
|
except Exception as e:
|
|
182
182
|
return False
|
|
183
|
+
|
|
183
184
|
def getConfig(self, key: str, default: Any = None) -> Any:
|
|
184
185
|
"""
|
|
185
186
|
获取模块/适配器配置项
|
|
@@ -188,21 +189,8 @@ class EnvManager:
|
|
|
188
189
|
:return: 配置项的值
|
|
189
190
|
"""
|
|
190
191
|
try:
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
with open(self.CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
195
|
-
config = toml.load(f)
|
|
196
|
-
|
|
197
|
-
# 支持点分隔符访问嵌套配置
|
|
198
|
-
keys = key.split('.')
|
|
199
|
-
value = config
|
|
200
|
-
for k in keys:
|
|
201
|
-
if k not in value:
|
|
202
|
-
return default
|
|
203
|
-
value = value[k]
|
|
204
|
-
|
|
205
|
-
return value
|
|
192
|
+
from .config import config
|
|
193
|
+
return config.getConfig(key, default)
|
|
206
194
|
except Exception as e:
|
|
207
195
|
from . import logger
|
|
208
196
|
logger.error(f"读取配置文件 {self.CONFIG_FILE} 失败: {e}")
|
|
@@ -216,24 +204,8 @@ class EnvManager:
|
|
|
216
204
|
:return: 操作是否成功
|
|
217
205
|
"""
|
|
218
206
|
try:
|
|
219
|
-
config
|
|
220
|
-
|
|
221
|
-
with open(self.CONFIG_FILE, "r", encoding="utf-8") as f:
|
|
222
|
-
config = toml.load(f)
|
|
223
|
-
|
|
224
|
-
# 支持点分隔符设置嵌套配置
|
|
225
|
-
keys = key.split('.')
|
|
226
|
-
current = config
|
|
227
|
-
for k in keys[:-1]:
|
|
228
|
-
if k not in current:
|
|
229
|
-
current[k] = {}
|
|
230
|
-
current = current[k]
|
|
231
|
-
current[keys[-1]] = value
|
|
232
|
-
|
|
233
|
-
with open(self.CONFIG_FILE, "w", encoding="utf-8") as f:
|
|
234
|
-
toml.dump(config, f)
|
|
235
|
-
|
|
236
|
-
return True
|
|
207
|
+
from .config import config
|
|
208
|
+
return config.setConfig(key, value)
|
|
237
209
|
except Exception as e:
|
|
238
210
|
from . import logger
|
|
239
211
|
logger.error(f"写入配置文件 {self.CONFIG_FILE} 失败: {e}")
|
ErisPulse/Core/logger.py
CHANGED
|
@@ -119,7 +119,6 @@ class Logger:
|
|
|
119
119
|
# 使用自定义格式化器去除rich markup标签
|
|
120
120
|
file_handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
|
|
121
121
|
self._logger.addHandler(file_handler)
|
|
122
|
-
self._logger.info(f"日志输出已设置到文件: {p}")
|
|
123
122
|
return True
|
|
124
123
|
except Exception as e:
|
|
125
124
|
self._logger.error(f"无法设置日志文件 {p}: {e}")
|
|
@@ -175,17 +174,15 @@ class Logger:
|
|
|
175
174
|
self._logs[ModuleName].append(msg)
|
|
176
175
|
|
|
177
176
|
def _setup_config(self):
|
|
178
|
-
from .
|
|
179
|
-
|
|
180
|
-
if "
|
|
181
|
-
logger_config
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
self.set_memory_limit(logger_config["memory_limit"])
|
|
188
|
-
|
|
177
|
+
from .config import get_logger_config
|
|
178
|
+
logger_config = get_logger_config()
|
|
179
|
+
if "level" in logger_config:
|
|
180
|
+
self.set_level(logger_config["level"])
|
|
181
|
+
if "log_files" in logger_config and logger_config["log_files"]:
|
|
182
|
+
self.set_output_file(logger_config["log_files"])
|
|
183
|
+
if "memory_limit" in logger_config:
|
|
184
|
+
self.set_memory_limit(logger_config["memory_limit"])
|
|
185
|
+
|
|
189
186
|
def _get_effective_level(self, module_name):
|
|
190
187
|
return self._module_levels.get(module_name, self._logger.level)
|
|
191
188
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ErisPulse/__init__.py,sha256=T-N56UQyBmpvlqwH2wGi5ptPzaJpbgF5tKkJt0DlkaM,26099
|
|
2
|
+
ErisPulse/__main__.py,sha256=QwHMu8lmWbjS3EyOYV-wea3I0xcGmH_McWNx7JSGwts,24853
|
|
3
|
+
ErisPulse/Core/__init__.py,sha256=tBYPahQ7-w7U6M69xy8DW0_ECa9ja-Q0y_SQqVswYBo,409
|
|
4
|
+
ErisPulse/Core/adapter.py,sha256=ZK81dibJ471FowL0MRXkS113iBcMgj_VzpTw0PzhAEo,18102
|
|
5
|
+
ErisPulse/Core/config.py,sha256=ZmwGdtHSOE7K5uOGzLYcyl3ZF3sAmeWAntqcdfDzhpM,5027
|
|
6
|
+
ErisPulse/Core/env.py,sha256=HGkzsdbxh8c1GSDJhnGP9B09Sz2ZeNbRxWieaFmAcug,18870
|
|
7
|
+
ErisPulse/Core/logger.py,sha256=3PPwJVcIM_TZerGGK_68vCdxsR0owrhyek3iyugGVg0,8295
|
|
8
|
+
ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
|
|
9
|
+
ErisPulse/Core/raiserr.py,sha256=vlyaaiOIYkyqm9dAqSW9E54JBzX-9roHDp5_r6I0yUU,5591
|
|
10
|
+
ErisPulse/Core/server.py,sha256=FkDTeLuHD5IBnWVxvYU8pHb6yCt8GzyvC1bpOiJ7G7I,9217
|
|
11
|
+
ErisPulse/Core/util.py,sha256=7rdMmn6sBFqYd4znxBCcJjuv2eyTExdeKyZopgds868,3796
|
|
12
|
+
erispulse-2.1.10.dist-info/METADATA,sha256=3J5J1MQYsOgZLgNmtcOwMnlh7AezJmAuaVAPwrQNRaw,6259
|
|
13
|
+
erispulse-2.1.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
erispulse-2.1.10.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
|
|
15
|
+
erispulse-2.1.10.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
|
|
16
|
+
erispulse-2.1.10.dist-info/RECORD,,
|
erispulse-2.1.8.dist-info/RECORD
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
ErisPulse/__init__.py,sha256=T-N56UQyBmpvlqwH2wGi5ptPzaJpbgF5tKkJt0DlkaM,26099
|
|
2
|
-
ErisPulse/__main__.py,sha256=QwHMu8lmWbjS3EyOYV-wea3I0xcGmH_McWNx7JSGwts,24853
|
|
3
|
-
ErisPulse/Core/__init__.py,sha256=xmz9RzIbM6umY-3FNFMLC5Pht7yBCH70XJG4Ehv0veU,1249
|
|
4
|
-
ErisPulse/Core/adapter.py,sha256=lw5T336EsNtjUgSPdevcOZReZNkA8oYvvTRCHk_fo_o,18149
|
|
5
|
-
ErisPulse/Core/env.py,sha256=D2BwtSbKggbeAsOzwwVv-kd5UkVmYlDUHtgLzFZqKUI,19841
|
|
6
|
-
ErisPulse/Core/logger.py,sha256=4ZEdX2CB9L6WQH-GNKN-p_qpiZnwJr_w9Q9P0zF8U44,8451
|
|
7
|
-
ErisPulse/Core/mods.py,sha256=2yIq8t9Ca9CBPRiZU0yr8Lc0XGmmkB7LlH-5FWqXjw4,7023
|
|
8
|
-
ErisPulse/Core/raiserr.py,sha256=vlyaaiOIYkyqm9dAqSW9E54JBzX-9roHDp5_r6I0yUU,5591
|
|
9
|
-
ErisPulse/Core/server.py,sha256=FkDTeLuHD5IBnWVxvYU8pHb6yCt8GzyvC1bpOiJ7G7I,9217
|
|
10
|
-
ErisPulse/Core/util.py,sha256=7rdMmn6sBFqYd4znxBCcJjuv2eyTExdeKyZopgds868,3796
|
|
11
|
-
erispulse-2.1.8.dist-info/METADATA,sha256=g9cby76kIhcKukKJv508YJ0TOCqNv6doqQgmzwJkyfE,6258
|
|
12
|
-
erispulse-2.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
13
|
-
erispulse-2.1.8.dist-info/entry_points.txt,sha256=Jss71M6nEha0TA-DyVZugPYdcL14s9QpiOeIlgWxzOc,182
|
|
14
|
-
erispulse-2.1.8.dist-info/licenses/LICENSE,sha256=4jyqikiB0G0n06CEEMMTzTXjE4IShghSlB74skMSPQs,1464
|
|
15
|
-
erispulse-2.1.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|