You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
951 B

  1. import configparser
  2. import re
  3. import os.path as osp
  4. # https://stackoverflow.com/a/11866695
  5. ROOT = osp.dirname(__file__)
  6. CONFIG_PATH = osp.join(ROOT, "config.ini")
  7. class AdbConfig(configparser.ConfigParser):
  8. def __init__(self):
  9. super().__init__(interpolation=configparser.ExtendedInterpolation())
  10. def getlist(self, section, option, fallback=None):
  11. data = self.get(section, option, fallback=fallback)
  12. if data == fallback:
  13. return data
  14. return list(filter(bool, re.split(" *, *", data)))
  15. def getpath(self, section, option, fallback=None):
  16. data = self.get(section, option, fallback=fallback)
  17. if data == fallback:
  18. return data
  19. return osp.expandvars(data)
  20. def getpaths(self, section, option, fallback=None):
  21. data = self.getlist(section, option, fallback)
  22. return list(map(osp.expandvars, data))
  23. config = AdbConfig()
  24. config.read(CONFIG_PATH)