GetConfig.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: GetConfig.py
  5. Description : fetch config from config.ini
  6. Author : JHao
  7. date: 2016/12/3
  8. -------------------------------------------------
  9. Change Activity:
  10. 2016/12/3: get db property func
  11. -------------------------------------------------
  12. """
  13. __author__ = 'JHao'
  14. import os
  15. from Util.utilClass import ConfigParse
  16. from Util.utilClass import LazyProperty
  17. class GetConfig(object):
  18. """
  19. to get config from config.ini
  20. """
  21. def __init__(self):
  22. self.pwd = os.path.split(os.path.realpath(__file__))[0]
  23. self.config_path = os.path.join(os.path.split(self.pwd)[0], 'config.ini')
  24. self.config_file = ConfigParse()
  25. self.config_file.read(self.config_path)
  26. @LazyProperty
  27. def db_type(self):
  28. return self.config_file.get('DB', 'type')
  29. @LazyProperty
  30. def db_name(self):
  31. return self.config_file.get('DB', 'name')
  32. @LazyProperty
  33. def db_host(self):
  34. return self.config_file.get('DB', 'host')
  35. @LazyProperty
  36. def db_port(self):
  37. return int(self.config_file.get('DB', 'port'))
  38. @LazyProperty
  39. def proxy_getter_functions(self):
  40. return self.config_file.options('ProxyGetter')
  41. if __name__ == '__main__':
  42. gg = GetConfig()
  43. print gg.db_type
  44. print gg.db_name
  45. print gg.db_host
  46. print gg.db_port
  47. print gg.proxy_getter_functions