config_util.py 799 B

12345678910111213141516171819202122232425262728
  1. import configparser
  2. import os
  3. class ConfigUtil:
  4. _config = None
  5. _loaded = False
  6. @classmethod
  7. def _init(cls):
  8. if cls._loaded:
  9. return
  10. config_path = os.path.join(os.path.dirname(__file__), '../config.ini')
  11. parser = configparser.ConfigParser()
  12. parser.read(config_path, encoding='utf-8')
  13. cls._config = parser
  14. cls._loaded = True
  15. @classmethod
  16. def get(cls, section, option, fallback=None):
  17. cls._init()
  18. return cls._config.get(section, option, fallback=fallback)
  19. @classmethod
  20. def get_list(cls, section, option, sep=',', fallback=None):
  21. value = cls.get(section, option, fallback)
  22. if value is not None:
  23. return [v.strip() for v in value.split(sep)]
  24. return fallback