Spaces:
Sleeping
Sleeping
File size: 1,038 Bytes
72a1159 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import configparser
from utils import static_init
@static_init
class GlobalConfig:
default_file_name = "config.ini"
config = configparser.ConfigParser()
@classmethod
def get_section(cls, section_name):
if section_name in cls.config :
return cls.config[section_name].keys()
else:
return None
@classmethod
def get(cls, section_name, attr_name):
if section_name in cls.config and attr_name in cls.config[section_name]:
value = cls.config.get(section_name, attr_name)
value = value.split(":")
type_name = value[0]
value = ":".join(value[1:])
if type_name == "str":
value = str(value)
elif type_name == "float":
value = float(value)
elif type_name == "int":
value = int(value)
return value
else:
return None
@classmethod
def __static_init__(cls):
cls.config.read(cls.default_file_name)
|