| 12345678910111213141516171819202122232425262728 |
- import configparser
- import os
- class ConfigUtil:
- _config = None
- _loaded = False
- @classmethod
- def _init(cls):
- if cls._loaded:
- return
- config_path = os.path.join(os.path.dirname(__file__), '../config.ini')
- parser = configparser.ConfigParser()
- parser.read(config_path, encoding='utf-8')
- cls._config = parser
- cls._loaded = True
- @classmethod
- def get(cls, section, option, fallback=None):
- cls._init()
- return cls._config.get(section, option, fallback=fallback)
- @classmethod
- def get_list(cls, section, option, sep=',', fallback=None):
- value = cls.get(section, option, fallback)
- if value is not None:
- return [v.strip() for v in value.split(sep)]
- return fallback
|