file.py 1.38 KB
Newer Older
崔为之's avatar
崔为之 committed
1 2 3 4 5 6 7 8 9 10 11 12
#!/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/3 19:58
# @File        : file.py
# @Description :
"""

崔为之's avatar
崔为之 committed
13 14 15 16
from typing import Optional

from application.constants import DEFAULT_CONFIG, ENV_CONFIG_MAP

崔为之's avatar
崔为之 committed
17 18 19 20 21 22 23 24 25

class FileHelper:
    """
    FileHelper is a utility class that provides file-related operations.
    Currently, it only provides a method to get the configuration file name
    based on the environment.
    """

    @classmethod
崔为之's avatar
崔为之 committed
26
    def get_filename(cls, env: Optional[str]) -> str:
崔为之's avatar
崔为之 committed
27 28 29 30
        """
        Get the configuration file name based on the environment.

        :param env: a string representing the environment.
崔为之's avatar
崔为之 committed
31
                    It should be one of the keys in ENV_CONFIG_MAP, or None.
崔为之's avatar
崔为之 committed
32 33
        :return: a string representing the configuration file name.
        """
崔为之's avatar
崔为之 committed
34
        return ENV_CONFIG_MAP.get(env, DEFAULT_CONFIG)
崔为之's avatar
崔为之 committed
35 36 37 38 39 40 41 42 43 44 45 46 47

    def __repr__(self):
        """
        Return a string representing a valid Python expression that could be used
        to recreate the FileHelper object.
        """
        return "FileHelper()"

    def __str__(self):
        """
        Return a human-readable string representation of the FileHelper object.
        """
        return "This is a FileHelper class that helps with file related operations."