diff --git a/application/common/file.py b/application/common/file.py index 2ac383e8a7592c543113ff56e1ca09ae8a0a4140..577a1c469ceef6f45054d43829b0d1e016d88e32 100644 --- a/application/common/file.py +++ b/application/common/file.py @@ -10,6 +10,10 @@ # @Description : """ +from typing import Optional + +from application.constants import DEFAULT_CONFIG, ENV_CONFIG_MAP + class FileHelper: """ @@ -19,20 +23,15 @@ class FileHelper: """ @classmethod - def get_filename(cls, env: str) -> str: + def get_filename(cls, env: Optional[str]) -> str: """ Get the configuration file name based on the environment. :param env: a string representing the environment. - It should be 'PRODUCTION' or None. + It should be one of the keys in ENV_CONFIG_MAP, or None. :return: a string representing the configuration file name. - If env is 'PRODUCTION', return 'production_config.yaml'. - Otherwise, return 'config.yaml'. """ - if env == 'PRODUCTION': - return f'{env.lower()}_config.yaml' - else: - return 'config.yaml' + return ENV_CONFIG_MAP.get(env, DEFAULT_CONFIG) def __repr__(self): """ diff --git a/application/constants/__init__.py b/application/constants/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8e0bfb49021dd4ac141e4fd8a368e57406e334f7 --- /dev/null +++ b/application/constants/__init__.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +# @Version : Python 3.11.4 +# @Software : Sublime Text 4 +# @Author : StudentCWZ +# @Email : StudentCWZ@outlook.com +# @Date : 2023/11/4 15:08 +# @File : __init__.py.py +# @Description : +""" + +from .constants import DEFAULT_CONFIG, ENV_CONFIG_MAP diff --git a/application/constants/constants.py b/application/constants/constants.py new file mode 100644 index 0000000000000000000000000000000000000000..404ebe18b66f3f093068bab77d99764a15ee35a6 --- /dev/null +++ b/application/constants/constants.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +# @Version : Python 3.11.4 +# @Software : Sublime Text 4 +# @Author : StudentCWZ +# @Email : StudentCWZ@outlook.com +# @Date : 2023/11/4 15:08 +# @File : constants.py +# @Description : +""" + +DEFAULT_CONFIG = 'config.yaml' + +ENV_CONFIG_MAP = { + 'PRODUCTION': 'production_config.yaml', + 'DEVELOPMENT': 'config.yaml', + # Add more environments here if necessary +}