cfg
配置文件模块
attribute
NoneType= type(None)
attribute
VERSION= tuple[int, int, int]
attribute
PLUGINCFG_DEFAULT= {'配置版本': '0.0.1', '配置项': None}
attribute
PLUGINCFG_STANDARD_TYPE= {'配置版本': str, '配置项': [type(None), dict]}
attribute
default_cfg= write_default_cfg_file
func
_cfg_isinstance_single(obj, typ) -> bool
param
objAny
param
typtype
Returns
bool
func
_cfg_isinstance(obj, typ)
专用于 Cfg 的类型检测
Args: obj (Any): 待检测对象 typ (Any | tuple[Any]): 类型或类型元组
Returns: bool: 是否为对应类型
param
objAny
param
typtype | tuple[type]
Returns
None
func
_get_cfg_type_name(typ) -> str
转换类型为中文字符串
Args: typ (Any): 类型
Returns: str: 中文字符串
param
typAny
Returns
str
func
get_cfg(path, standard_type)
从 path 路径获取 json 文件文本信息,并按照 standard_type 给出的标准形式进行检测。
param
pathstr | Path
param
standard_typeAny
Returns
None
func
get_plugin_config_and_version(plugin_name, schema, default, default_vers) -> tuple[dict[str, Any], VERSION]
获取插件配置文件及版本
Args: plugin_name (str): 插件名 schema (dict): 配置模版 default (dict): 默认配置 default_vers (tuple[int, int, int]): 默认版本
Returns: tuple[dict[str, Any], tuple[int, int, int]]: 配置文件内容及版本
param
plugin_namestr
param
schemaAny
param
defaultdict
param
default_versVERSION
Returns
tuple[dict[str, typing.Any], tooldelta.utils.cfg.VERSION]
func
upgrade_plugin_config(plugin_name, configs, version)
获取插件配置文件及版本
Args: plugin_name (str): 插件名 configs (dict): 配置内容 default_vers (tuple[int, int, int]): 版本
param
plugin_namestr
param
configsdict
param
versionVERSION
Returns
None
func
check_auto(standard, val, fromkey='?')
检测任意类型的 json 类型是否合法
Args: standard (type, dict, list): 标准模版 val (Any): 待检测的值 fromkey (Any, optional): 从哪个json键向下检索而来
Raises: ValueError: 未知标准检测类型 ConfigValueError: 值错误
param
standardAny
param
valAny
param
fromkeystr
= '?'
Returns
None
func
auto_to_std(cfg)
从默认的配置文件内容的字典自动生成检测模版 注意: 无法自动检测 AnyKeyValue, KeyGroup, PInt, PFloat 等
Args: cfg: 默认的配置文件内容的字典
Returns: 标准检测模版样式, 用于 check_dict
param
cfgReturns
None
func
check_dict(pattern, jsondict, from_key='?')
按照给定的标准配置样式比对传入的字典, 键值对不上模版则引发相应异常 请改为使用 check_auto
参数: pattern: 标准模版 dict jsondict: 待检测的配置文件 dict
param
patternAny
param
jsondictAny
param
from_key= '?'
Returns
None
func
check_list(pattern, value, fromkey='?') -> None
检查列表是否合法 请改为使用 check_auto
Args: pattern (list): 标准模版 value (Any): 待检测值 fromkey (Any, optional): 从哪个字典键向下检索而来
Raises: ValueError: 不是合法的标准列表检测样式 ValueError: 标准检测列表的长度不能为 0 ConfigValueError: 值错误
param
patternJsonList
param
valueAny
param
fromkeyAny
= '?'
Returns
None
func
write_default_cfg_file(path, default, force=False) -> None
生成默认配置文件
Args: path (str): 路径 default (dict): 默认配置 force (bool, optional): 是否即使是配置文件存在时, 也强制覆盖内容.
param
pathstr
param
defaultdict
param
forcebool
= False
Returns
None
func
_jsonfile_exists(path) -> bool
param
pathstr
Returns
bool