config.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import os.path
  4. import json
  5. from monomotapa.pparams import DEVELOPMENT, DEPLOYMENT, CONFIG_FILE
  6. from monomotapa.pparams import CLAVE1, CLAVE2, CARPETA_BACKUPS
  7. from monomotapa.pparams import CARPETA_DEPLOY
  8. class Config(object):
  9. """load config values e.g default css"""
  10. def __init__(self, conffile):
  11. try:
  12. config_file = self.get_config_file(conffile)
  13. except NameError:
  14. raise ConfigError("Config file %s not found" % conffile)
  15. with open(config_file, 'r') as cfile:
  16. self.config = json.load(cfile)
  17. def get_config_file(self, filename):
  18. """return first file found in path"""
  19. config_file = None
  20. path_to_app = sys.path[0]
  21. # path = [
  22. # filename,
  23. # os.path.join(path_to_app, filename),
  24. # os.path.join('/etc/monmotapa/', filename),
  25. # os.path.join('/etc', filename)
  26. # ]
  27. path = [
  28. filename,
  29. os.path.join(path_to_app, filename),
  30. os.path.join(CARPETA_DEPLOY, filename),
  31. os.path.join('/etc', filename)
  32. ]
  33. for cfile in path:
  34. if os.path.exists(cfile):
  35. config_file = cfile
  36. break
  37. return config_file
  38. class ConfigError(Exception):
  39. pass