aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/config.py
blob: fe581d0848de2536089b36a3160e5ace39ba0e89 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. import json
  4. import os.path
  5. from configparser import SafeConfigParser
  6. from lib.args import Args
  7. import lib.connection as Connection
  8. __all__ = ['Config']
  9. def getlist(self, section, option):
  10. return [x.strip() for x in self.get(section, option).split(',')]
  11. def fetchServerConfig(self):
  12. log = logging.getLogger('Config')
  13. log.info("reading server-config")
  14. server_config = Connection.fetchServerConfig()
  15. log.info("merging server-config %s", server_config)
  16. self.read_dict(server_config)
  17. SafeConfigParser.getlist = getlist
  18. SafeConfigParser.fetchServerConfig = fetchServerConfig
  19. files = [
  20. os.path.join(os.path.dirname(os.path.realpath(__file__)), '../default-config.ini'),
  21. os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.ini'),
  22. '/etc/voctogui.ini',
  23. os.path.expanduser('~/.voctogui.ini'),
  24. ]
  25. if Args.ini_file is not None:
  26. files.append(Args.ini_file)
  27. Config = SafeConfigParser()
  28. Config.read(files)