GetConfig.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. """
  4. -------------------------------------------------
  5. File Name: GetConfig.py
  6. Description : fetch config from config.ini
  7. Author : JHao
  8. date: 2016/12/3
  9. -------------------------------------------------
  10. Change Activity:
  11. 2016/12/3: get db property func
  12. -------------------------------------------------
  13. """
  14. __author__ = 'JHao'
  15. import os
  16. from Util.utilClass import ConfigParse
  17. from Util.utilClass import LazyProperty
  18. class GetConfig(object):
  19. """
  20. to get config from config.ini
  21. """
  22. def __init__(self):
  23. self.pwd = os.path.split(os.path.realpath(__file__))[0]
  24. self.config_path = os.path.join(os.path.split(self.pwd)[0], 'Config.ini')
  25. self.config_file = ConfigParse(defaults={"password": None})
  26. self.config_file.read(self.config_path)
  27. @LazyProperty
  28. def db_type(self):
  29. return self.config_file.get('DB', 'type')
  30. @LazyProperty
  31. def db_name(self):
  32. return self.config_file.get('DB', 'name')
  33. @LazyProperty
  34. def db_host(self):
  35. return self.config_file.get('DB', 'host')
  36. @LazyProperty
  37. def db_port(self):
  38. return int(self.config_file.get('DB', 'port'))
  39. @LazyProperty
  40. def db_password(self):
  41. return self.config_file.get('DB', 'password')
  42. @LazyProperty
  43. def proxy_getter_functions(self):
  44. return self.config_file.options('ProxyGetter')
  45. @LazyProperty
  46. def host_ip(self):
  47. return self.config_file.get('API', 'ip')
  48. @LazyProperty
  49. def host_port(self):
  50. return int(self.config_file.get('API', 'port'))
  51. config = GetConfig()
  52. if __name__ == '__main__':
  53. gg = GetConfig()
  54. print(gg.db_type)
  55. print(gg.db_name)
  56. print(gg.db_host)
  57. print(gg.db_port)
  58. print(gg.proxy_getter_functions)
  59. print(gg.host_ip)
  60. print(gg.host_port)
  61. print(gg.db_password)