ErisPulse 2.1.8__tar.gz → 2.1.10__tar.gz
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-2.1.8 → erispulse-2.1.10}/PKG-INFO +1 -1
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/CHANGELOG.md +5 -1
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-adapter/MyAdapter/Core.py +12 -10
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-module/MyModule/Core.py +15 -16
- {erispulse-2.1.8 → erispulse-2.1.10}/pyproject.toml +1 -1
- erispulse-2.1.10/src/ErisPulse/Core/__init__.py +21 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/adapter.py +3 -6
- erispulse-2.1.10/src/ErisPulse/Core/config.py +172 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/env.py +5 -33
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/logger.py +9 -12
- erispulse-2.1.8/src/ErisPulse/Core/__init__.py +0 -57
- {erispulse-2.1.8 → erispulse-2.1.10}/.github/assets/erispulse_logo.png +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.github/tools/merge_md.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.github/tools/update-api-docs.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.github/workflows/auto-tag-release.yml +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.github/workflows/pypi-publish.yml +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.gitignore +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/.python-version +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/CODE_OF_CONDUCT.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/LICENSE +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/devs/test.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/devs/test_adapter.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/devs/test_files/test.docx +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/devs/test_files/test.jpg +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/devs/test_files/test.mp4 +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIDocs/ErisPulse-AdapterDev.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIDocs/ErisPulse-Core.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIDocs/ErisPulse-Full.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIDocs/ErisPulse-ModuleDev.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIDocs/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AIModuleGeneration.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AdapterStandards/APIResponse.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AdapterStandards/EventConversion.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/AdapterStandards/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/CHANGELOG_1.x.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/CLI.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/Development/Adapter.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/Development/CLI.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/Development/Module.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/Development/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/PlatformFeatures.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/UseCore.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/adapter.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/env.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/logger.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/mods.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/raiserr.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/server.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/Core/util.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/__init__.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/ErisPulse/__main__.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/api/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/docs/quick-start.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-adapter/LICENSE +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-adapter/MyAdapter/__init__.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-adapter/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-adapter/pyproject.toml +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-cli-module/LICENSE +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-cli-module/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-cli-module/my_cli_module/__init__.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-cli-module/my_cli_module/cli.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-cli-module/pyproject.toml +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-module/LICENSE +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-module/MyModule/__init__.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-module/README.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/examples/example-module/pyproject.toml +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/scripts/install/install.ps1 +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/scripts/install/install.sh +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/mods.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/raiserr.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/server.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/Core/util.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/__init__.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/src/ErisPulse/__main__.py +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/style_guide/DOCSTRING_SPEC.md +0 -0
- {erispulse-2.1.8 → erispulse-2.1.10}/style_guide/README.md +0 -0
|
@@ -8,10 +8,14 @@
|
|
|
8
8
|
> **贡献日志**
|
|
9
9
|
> 如需为新版本添加日志,请在对应版本号下补充内容,并注明日期和主要贡献者。
|
|
10
10
|
|
|
11
|
-
## [2.1.
|
|
11
|
+
## [2.1.10] - 2025/07/20
|
|
12
|
+
### 新增
|
|
13
|
+
- 新增 `config` 模块,用于分离 `env` 模块功能,提供更友好的配置管理体验
|
|
12
14
|
|
|
13
15
|
### 变更
|
|
14
16
|
- 标准日志处理器替换为RichHandler,提供更美观的彩色控制台日志输出
|
|
17
|
+
- 使用独立的 `Config` 模块处理核心配置,避免与 `env` 模块冲突
|
|
18
|
+
- 兼容性性改进:解决情况下部分循环引用问题
|
|
15
19
|
|
|
16
20
|
### 修复
|
|
17
21
|
- 修复设置模块日志等级时,调用错误的问题
|
|
@@ -12,24 +12,26 @@ class MyAdapter(BaseAdapter):
|
|
|
12
12
|
self.logger = self.sdk.logger
|
|
13
13
|
|
|
14
14
|
self.logger.info("MyModule 初始化完成")
|
|
15
|
-
self.
|
|
15
|
+
self.config = self._load_config()
|
|
16
|
+
|
|
16
17
|
# 加载配置方法,你需要在这里进行必要的配置加载逻辑
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
self.logger.error("请在env.py中添加MyAdapter配置")
|
|
22
|
-
self.env.setConfig("MyAdapter", {
|
|
18
|
+
def _load_config(self):
|
|
19
|
+
_config = self.env.getConfig("MyAdapter", {})
|
|
20
|
+
if _config is None:
|
|
21
|
+
default_config = {
|
|
23
22
|
"mode": "server",
|
|
24
23
|
"server": {
|
|
25
|
-
"
|
|
26
|
-
"port": 8080
|
|
24
|
+
"path": "/webhook",
|
|
27
25
|
},
|
|
28
26
|
"client": {
|
|
29
27
|
"url": "http://127.0.0.1:8080",
|
|
30
28
|
"token": ""
|
|
31
29
|
}
|
|
32
|
-
}
|
|
30
|
+
}
|
|
31
|
+
self.env.setConfig("MyAdapter", default_config)
|
|
32
|
+
return default_config
|
|
33
|
+
return _config
|
|
34
|
+
|
|
33
35
|
class Send(BaseAdapter.Send): # 继承BaseAdapter内置的Send类
|
|
34
36
|
# 底层SendDSL中提供了To方法,用户调用的时候类会被定义 `self._target_type` 和 `self._target_id`/`self._target_to` 三个属性
|
|
35
37
|
# 当你只需要一个接受的To时,例如 mail 的To只是一个邮箱,那么你可以使用 `self.To(email)`,这时只会有 `self._target_id`/`self._target_to` 两个属性被定义
|
|
@@ -9,23 +9,22 @@ class Main:
|
|
|
9
9
|
self.logger = self.sdk.logger
|
|
10
10
|
|
|
11
11
|
self.logger.info("MyModule 初始化完成")
|
|
12
|
-
self.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"key1": "value1",
|
|
22
|
-
"key2": ["value2", "value3"],
|
|
12
|
+
self.config = self._load_config()
|
|
13
|
+
|
|
14
|
+
# 加载配置方法,你需要在这里进行必要的配置加载逻辑
|
|
15
|
+
def _load_config(self):
|
|
16
|
+
_config = self.env.getConfig("MyModule", {})
|
|
17
|
+
if _config is None:
|
|
18
|
+
default_config = {
|
|
19
|
+
"key": "value",
|
|
20
|
+
"key2": [1, 2, 3],
|
|
23
21
|
"key3": {
|
|
24
|
-
"key4": "value4"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
"key4": "value4"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
self.env.setConfig("MyModule", default_config)
|
|
26
|
+
return default_config
|
|
27
|
+
return _config
|
|
29
28
|
|
|
30
29
|
def hello(self):
|
|
31
30
|
self.logger.info("Hello World!")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .adapter import AdapterFather, SendDSL, adapter
|
|
2
|
+
from .env import env
|
|
3
|
+
from .logger import logger
|
|
4
|
+
from .mods import mods
|
|
5
|
+
from .raiserr import raiserr
|
|
6
|
+
from .util import util
|
|
7
|
+
from .server import adapter_server
|
|
8
|
+
BaseAdapter = AdapterFather
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'BaseAdapter',
|
|
12
|
+
'AdapterFather',
|
|
13
|
+
'SendDSL',
|
|
14
|
+
'adapter',
|
|
15
|
+
'env',
|
|
16
|
+
'logger',
|
|
17
|
+
'mods',
|
|
18
|
+
'raiserr',
|
|
19
|
+
'util',
|
|
20
|
+
'adapter_server'
|
|
21
|
+
]
|
|
@@ -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,
|
|
@@ -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"]
|
|
@@ -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}")
|
|
@@ -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
|
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
from .adapter import AdapterFather, SendDSL, adapter
|
|
2
|
-
from .env import env
|
|
3
|
-
from .logger import logger
|
|
4
|
-
from .mods import mods
|
|
5
|
-
from .raiserr import raiserr
|
|
6
|
-
from .util import util
|
|
7
|
-
from .server import adapter_server
|
|
8
|
-
BaseAdapter = AdapterFather
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
'BaseAdapter',
|
|
12
|
-
'AdapterFather',
|
|
13
|
-
'SendDSL',
|
|
14
|
-
'adapter',
|
|
15
|
-
'env',
|
|
16
|
-
'logger',
|
|
17
|
-
'mods',
|
|
18
|
-
'raiserr',
|
|
19
|
-
'util',
|
|
20
|
-
'adapter_server'
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|