config.processor.tarfile

Tar压缩配置文件处理器

在 0.2.0 版本加入.

Classes

TarCompressionType

压缩类型数据结构

TarCompressionTypes

压缩类型

TarFileSL

tar格式处理器

Module Contents

class TarCompressionType

压缩类型数据结构

full_name: str
short_name: str | None
class TarCompressionTypes

Bases: TarCompressionType, enum.ReprEnum

压缩类型

BZIP2 = ('bzip2', 'bz2')
GZIP = ('gzip', 'gz')
LZMA = ('lzma', 'xz')
ONLY_STORAGE = ('only-storage', None)
full_name: str
short_name: str | None
class TarFileSL(*, reg_alias: str | None = None, create_dir: bool = True, compression: TarCompressionTypes | str | None = TarCompressionTypes.ONLY_STORAGE, compress_level: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | int | None = None, extraction_filter: ExtractionFilter | None = 'data')

Bases: config.main.BasicCompressedConfigSL

tar格式处理器

参数:
  • reg_alias (str | None) -- sl处理器注册别名

  • create_dir (bool) -- 是否创建目录

  • compression (TarCompressionTypes | str | None) -- 压缩类型

  • compress_level (Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | int | None) -- 压缩等级

  • extraction_filter (ExtractionFilter | None) -- 解压过滤器

__eq__(other: Any) bool
__hash__() int
after_save(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], file_path: str, root_path: str, namespace: str, file_name: str) None

保存后处理

参数:
  • config_pool (ABCConfigPool) -- 配置池

  • config_file (ABCConfigFile[Any]) -- 配置文件

  • file_path (str) -- 文件路径

  • root_path (str) -- 根路径

  • namespace (str) -- 命名空间

  • file_name (str) -- 文件名

before_load(config_pool: config.abc.ABCConfigPool, file_path: str, root_path: str, namespace: str, file_name: str) None

加载前处理

参数:
  • config_pool (ABCConfigPool) -- 配置池

  • file_path (str) -- 文件路径

  • root_path (str) -- 根路径

  • namespace (str) -- 命名空间

  • file_name (str) -- 文件名

compress_file(file_path: str, extract_dir: str) None

压缩文件

参数:
  • file_path (str) -- 压缩文件路径

  • extract_dir (str) -- 解压目录

extract_file(file_path: str, extract_dir: str) None

解压文件

参数:
  • file_path (str) -- 压缩文件路径

  • extract_dir (str) -- 解压目录

filename_formatter(file_name: str) str

格式化文件名以传递给其他SL处理器

参数:

file_name (str) -- 配置文件名

返回:

格式化后的文件名

返回类型:

str

默认实现:
  • 遍历 BasicCompressedConfigSL

  • 如果为 strfile_name.endswith 成立则返回移除后缀后的结果

  • 如果为 re.PatternPattern.fullmatch(file_name) 成立则返回 Pattern.sub(file_name, "")

  • 直接返回

initialize(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.abc.ABCConfigFile[Any]

初始化一个受SL处理器支持的配置文件

参数:
  • processor_pool (ABCSLProcessorPool) -- 配置池

  • root_path (str) -- 保存的根目录

  • namespace (str) -- 配置的命名空间

  • file_name (str) -- 配置文件名

返回:

配置对象

返回类型:

ABCConfigFile

在 0.2.0 版本加入.

load(processor_pool: config.abc.ABCSLProcessorPool, root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.abc.ABCConfigFile[Any]

加载处理器

参数:
  • processor_pool (ABCSLProcessorPool) -- 配置池

  • root_path (str) -- 保存的根目录

  • namespace (str) -- 配置的命名空间

  • file_name (str) -- 配置文件名

返回:

配置对象

返回类型:

ABCConfigFile

抛出:

FailedProcessConfigFileError -- 处理配置文件失败

在 0.2.0 版本发生变更: 删除参数 config_file_cls

添加参数 processor_pool

load_file(config_pool: config.abc.ABCConfigPool, namespace: str, file_name: str, *args: Any, **kwargs: Any) config.abc.ABCConfigFile[Any]

加载指定命名空间的配置

参数:
  • config_pool (ABCConfigPool) -- 配置池

  • namespace (str) -- 命名空间

  • file_name (str) -- 文件名

返回:

配置文件

返回类型:

ABCConfigFile[Any]

小心

传递SL处理前没有清理已经缓存在配置池里的配置文件,返回的可能不是最新数据

namespace_formatter(namespace: str, file_name: str) str

格式化命名空间以传递给其他SL处理器

参数:
  • namespace (str) -- 配置的命名空间

  • file_name (str) -- 配置文件名

返回:

格式化后的命名空间

返回类型:

str

register_to(config_pool: config.abc.ABCSLProcessorPool | None = None) Self

注册到配置池中

参数:

config_pool (ABCSLProcessorPool | None) -- 配置池

返回:

返回当前实例便于链式调用

返回类型:

Self

在 0.3.0 版本发生变更: 返回当前实例便于链式调用

save(processor_pool: config.abc.ABCSLProcessorPool, config_file: config.abc.ABCConfigFile[Any], root_path: str, namespace: str, file_name: str, *args: Any, **kwargs: Any) None

保存处理器

参数:
  • processor_pool (ABCSLProcessorPool) -- 配置池

  • config_file (ABCConfigFile) -- 待保存配置

  • root_path (str) -- 保存的根目录

  • namespace (str) -- 配置的命名空间

  • file_name (str) -- 配置文件名

抛出:

FailedProcessConfigFileError -- 处理配置文件失败

在 0.2.0 版本发生变更: 添加参数 processor_pool

save_file(config_pool: config.abc.ABCConfigPool, config_file: config.abc.ABCConfigFile[Any], namespace: str, file_name: str, *args: Any, **kwargs: Any) None

保存指定命名空间的配置

参数:
__slots__ = ()
_cleanup_registry: bool = True

自动清理为了传递SL处理所加入配置池的配置文件

_compress_level: int | None = None
_compression: TarCompressionType
_extraction_filter: ExtractionFilter | None = 'data'
_reg_alias: str | None = None
_short_name = ''
create_dir = True
property namespace_suffix: str

命名空间后缀

property processor_reg_name: str

SL处理器的默认注册名

raises
property reg_alias: str | None

处理器的别名

property reg_name: str

处理器的注册名

supported_file_classes
返回:

支持的配置文件类

在 0.2.0 版本加入.

property supported_file_patterns: tuple[str, Ellipsis]
返回:

支持的文件名匹配

在 0.2.0 版本发生变更: 重命名 file_extsupported_file_patterns