new file: dependence.py
new file: package.py new file: packup.bat new file: packup.sh new file: requirements.txt new file: scripts/__init__.py new file: scripts/file_store_api.py new file: src/__init__.py new file: src/config.toml new file: src/modules/__init__.py new file: src/modules/plugin_modules.py new file: src/modules/user_module.py new file: src/process.py new file: test.py
This commit is contained in:
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
65
scripts/file_store_api.py
Normal file
65
scripts/file_store_api.py
Normal file
@ -0,0 +1,65 @@
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
import sqlite3
|
||||
import os
|
||||
import time
|
||||
import toml
|
||||
from pathlib import Path
|
||||
from http import HTTPStatus
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class ConfigManager:
|
||||
"""配置管理类,处理应用配置"""
|
||||
def __init__(self, config_path="src"):
|
||||
self.config = {}
|
||||
self.config_path = config_path
|
||||
self.build_config_dict()
|
||||
|
||||
|
||||
def build_config_dict(self) -> dict[str, str]:
|
||||
config_dict = {}
|
||||
for config_file in Path(self.config_path).rglob("*.toml"):
|
||||
if not config_file.is_file():
|
||||
continue
|
||||
|
||||
# 获取相对路径的父目录名
|
||||
rel_path = config_file.relative_to(self.config_path)
|
||||
parent_name = rel_path.parent.name if rel_path.parent.name else None
|
||||
|
||||
if parent_name:
|
||||
key = parent_name
|
||||
else:
|
||||
key = config_file.stem # 去掉扩展名
|
||||
|
||||
config_dict[key] = str(config_file.absolute())
|
||||
self.config = config_dict
|
||||
|
||||
def load_config(self,name):
|
||||
"""加载配置文件"""
|
||||
if not os.path.exists(self.config[name]):
|
||||
return {}
|
||||
with open(self.config[name], 'r', encoding='utf-8') as f:
|
||||
try:
|
||||
return toml.load(f)
|
||||
except toml.TomlDecodeError:
|
||||
return {}
|
||||
|
||||
def save_config(self, key=None, value=None):
|
||||
"""保存配置项"""
|
||||
if key is not None and value is not None:
|
||||
# 如果提供了 key 和 value,则更新单个值
|
||||
self.config[key] = value
|
||||
with open(self.config_path, 'w', encoding='utf-8') as f:
|
||||
toml.dump(self.config, f)
|
||||
|
||||
def update_config(self, config_dict):
|
||||
"""更新配置字典"""
|
||||
self.config.update(config_dict)
|
||||
self.save_config()
|
||||
|
||||
|
||||
class ChatManager:
|
||||
def __init__(self):
|
||||
return None
|
Reference in New Issue
Block a user