aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/config.py
blob: d4630bfe0eb4ee45ccb63de35448755623e36d4e (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__)), '../default-config.ini'),
  20. os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.ini'),
  21. '/etc/voctomix/voctogui.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)