ToolDelta ICU

cfg

配置文件模块

attributeNoneType
= type(None)
attributeVERSION
= tuple[int, int, int]
attributePLUGINCFG_DEFAULT
= {'配置版本': '0.0.1', '配置项': None}
attributePLUGINCFG_STANDARD_TYPE
= {'配置版本': str, '配置项': [type(None), dict]}
attributedefault_cfg
= write_default_cfg_file
func_cfg_isinstance_single(obj, typ) -> bool
paramobjAny
paramtyptype

Returns

bool
func_cfg_isinstance(obj, typ)

专用于 Cfg 的类型检测

Args: obj (Any): 待检测对象 typ (Any | tuple[Any]): 类型或类型元组

Returns: bool: 是否为对应类型

paramobjAny
paramtyptype | tuple[type]

Returns

None
func_get_cfg_type_name(typ) -> str

转换类型为中文字符串

Args: typ (Any): 类型

Returns: str: 中文字符串

paramtypAny

Returns

str
funcget_cfg(path, standard_type)

从 path 路径获取 json 文件文本信息,并按照 standard_type 给出的标准形式进行检测。

parampathstr | Path
paramstandard_typeAny

Returns

None
funcget_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]]: 配置文件内容及版本

paramplugin_namestr
paramschemaAny
paramdefaultdict
paramdefault_versVERSION

Returns

tuple[dict[str, typing.Any], tooldelta.utils.cfg.VERSION]
funcupgrade_plugin_config(plugin_name, configs, version)

获取插件配置文件及版本

Args: plugin_name (str): 插件名 configs (dict): 配置内容 default_vers (tuple[int, int, int]): 版本

paramplugin_namestr
paramconfigsdict
paramversionVERSION

Returns

None
funccheck_auto(standard, val, fromkey='?')

检测任意类型的 json 类型是否合法

Args: standard (type, dict, list): 标准模版 val (Any): 待检测的值 fromkey (Any, optional): 从哪个json键向下检索而来

Raises: ValueError: 未知标准检测类型 ConfigValueError: 值错误

paramstandardAny
paramvalAny
paramfromkeystr
= '?'

Returns

None
funcauto_to_std(cfg)

从默认的配置文件内容的字典自动生成检测模版 注意: 无法自动检测 AnyKeyValue, KeyGroup, PInt, PFloat 等

Args: cfg: 默认的配置文件内容的字典

Returns: 标准检测模版样式, 用于 check_dict

paramcfg

Returns

None
funccheck_dict(pattern, jsondict, from_key='?')

按照给定的标准配置样式比对传入的字典, 键值对不上模版则引发相应异常 请改为使用 check_auto

参数: pattern: 标准模版 dict jsondict: 待检测的配置文件 dict

parampatternAny
paramjsondictAny
paramfrom_key
= '?'

Returns

None
funccheck_list(pattern, value, fromkey='?') -> None

检查列表是否合法 请改为使用 check_auto

Args: pattern (list): 标准模版 value (Any): 待检测值 fromkey (Any, optional): 从哪个字典键向下检索而来

Raises: ValueError: 不是合法的标准列表检测样式 ValueError: 标准检测列表的长度不能为 0 ConfigValueError: 值错误

parampatternJsonList
paramvalueAny
paramfromkeyAny
= '?'

Returns

None
funcwrite_default_cfg_file(path, default, force=False) -> None

生成默认配置文件

Args: path (str): 路径 default (dict): 默认配置 force (bool, optional): 是否即使是配置文件存在时, 也强制覆盖内容.

parampathstr
paramdefaultdict
paramforcebool
= False

Returns

None
func_jsonfile_exists(path) -> bool
parampathstr

Returns

bool