From 5e0cb7817754dd96cab4d702cc82dc5365183bd1 Mon Sep 17 00:00:00 2001 From: cuiweizhi <560397@gree.com.cn> Date: Sat, 4 Nov 2023 15:12:24 +0800 Subject: [PATCH] Update project --- application/common/file.py | 15 +++++++-------- application/constants/__init__.py | 13 +++++++++++++ application/constants/constants.py | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 application/constants/__init__.py create mode 100644 application/constants/constants.py diff --git a/application/common/file.py b/application/common/file.py index 2ac383e..577a1c4 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 0000000..8e0bfb4 --- /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 0000000..404ebe1 --- /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 +} -- GitLab