import os from pathlib import Path from typing import Union, Dict class PathConfig: """文件路径配置类""" def __init__(self, base_dir: Union[str, Path] = None): # 设置基础目录,默认为当前工作目录 self.base_dir = Path(base_dir or os.getcwd()) # 定义各类文件的相对路径 self.paths = { 'audio_json': 'data/audio_json', 'output_filter_1': 'output/filter_1', 'output_filter_2': 'output/filter_2', 'output_filter_3': 'output/filter_3', 'output_filter_4': 'output/filter_4', 'frame_for_show': 'data/key_frame/for_show', 'caption_for_show': 'data/img_caption/for_show', 'aide_video': 'data/aide_video', 'sub_video': 'data/sub_video', 'exclude_word_json': 'config/exclude_word.json', 'include_word_json': 'config/include_word.json', 'Megrez-3B-Omni': '/data/data/luosy/models/Megrez-3B-Omni' } # 确保所有必要的目录存在 self._ensure_directories() def _ensure_directories(self): """确保所有必要的目录存在""" for path_key, path in self.paths.items(): full_path = self.base_dir / path if path.endswith('.json'): # 对于json文件,只创建其父目录 full_path.parent.mkdir(parents=True, exist_ok=True) else: # 对于目录,直接创建 full_path.mkdir(parents=True, exist_ok=True) def get_path(self, path_key: str) -> Path: """获取指定类型的完整路径""" if path_key not in self.paths: raise KeyError(f"未知的路径类型: {path_key}") return self.base_dir / self.paths[path_key] if __name__ == "__main__": # 创建全局路径配置实例 path_config = PathConfig() audio_name = Path("data/raw_video/test_video.flv").stem + ".json" audio_path = path_config.get_path('audio_json') / audio_name print((audio_path))