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