aboutsummaryrefslogtreecommitdiff
path: root/voctocore/lib/config.py
blob: 388778ee7370d179af2ff9ef72a60d2c068a8d74 (plain)
  1. import os.path
  2. import logging
  3. from configparser import SafeConfigParser
  4. from lib.args import Args
  5. __all__ = ['Config']
  6. def getlist(self, section, option):
  7. return [x.strip() for x in self.get(section, option).split(',')]
  8. SafeConfigParser.getlist = getlist
  9. files = [
  10. os.path.join(os.path.dirname(os.path.realpath(__file__)),
  11. '../default-config.ini'),
  12. os.path.join(os.path.dirname(os.path.realpath(__file__)),
  13. '../config.ini'),
  14. '/etc/voctomix/voctocore.ini',
  15. '/etc/voctomix.ini', # deprecated
  16. '/etc/voctocore.ini',
  17. os.path.expanduser('~/.voctomix.ini'), # deprecated
  18. os.path.expanduser('~/.voctocore.ini'),
  19. ]
  20. if Args.ini_file is not None:
  21. files.append(Args.ini_file)
  22. Config = SafeConfigParser()
  23. readfiles = Config.read(files)
  24. log = logging.getLogger('ConfigParser')
  25. log.debug('considered config-files: \n%s',
  26. "\n".join(["\t\t" + os.path.normpath(file) for file in files]))
  27. log.debug('successfully parsed config-files: \n%s',
  28. "\n".join(["\t\t" + os.path.normpath(file) for file in readfiles]))