def load_all_configs(cls): ''' 读取当前硬盘上所有DB_CONFIG 对应的json :return: None ''' config_path = DayuPath( os.environ.get( DAYU_CONFIG_STATIC_PATH, DayuPath(__file__).parent.child('static', cls.prefix + '_config_presets'))) assert config_path.exists() is True for json_preset in config_path.walk(): if json_preset.ext == '.json': with open(json_preset, 'r') as jf: preset_value = json.load(jf, encoding='utf-8') preset_key = json_preset.replace(config_path, '').replace('\\', '/') preset_key = preset_key.replace('.json', '').replace('default', '').strip('/') preset_key = cls.prefix + '.' + '.'.join( preset_key.split('/')) cls.all_configs.update({preset_key: preset_value}) return cls()
def load_all_configs(software=None): ''' 读取所有设置好的json 预设。需要json 文件存放在 sub_level_config_presets 文件内 必须在加载模块的时候运行一次! :return: ''' import os if software is None: software = os.getenv(DAYU_APP_NAME, '') root_path = DayuPath( os.environ.get( DAYU_CONFIG_STATIC_PATH, DayuPath(__file__).parent.child('static', presets_root, software))) for x in root_path.walk(filter=os.path.isfile): if x.endswith('.json'): with open(x, 'r') as jf: content = jf.read() if content: SUB_LEVEL_CONFIGS.update( {'.'.join(x.stem.split('_')): json.loads(content)})