GetConfig.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. from Util.utilClass import LazyProperty
  16. class GetConfig(object):
  17. """
  18. to get config from config.ini
  19. """
  20. def __init__(self):
  21. pass
  22. @LazyProperty
  23. def db_type(self):
  24. return self.config_file.get('DB', 'type')
  25. @LazyProperty
  26. def db_name(self):
  27. return self.config_file.get('DB', 'name')
  28. @LazyProperty
  29. def db_host(self):
  30. return self.config_file.get('DB', 'host')
  31. @LazyProperty
  32. def db_port(self):
  33. return int(self.config_file.get('DB', 'port'))
  34. @LazyProperty
  35. def db_password(self):
  36. return self.config_file.get('DB', 'password')
  37. @LazyProperty
  38. def proxy_getter_functions(self):
  39. return self.config_file.options('ProxyGetter')
  40. @LazyProperty
  41. def host_ip(self):
  42. return self.config_file.get('API', 'ip')
  43. @LazyProperty
  44. def host_port(self):
  45. return int(self.config_file.get('API', 'port'))
  46. config = GetConfig()
  47. if __name__ == '__main__':
  48. gg = GetConfig()
  49. print(gg.db_type)
  50. print(gg.db_name)
  51. print(gg.db_host)
  52. print(gg.db_port)
  53. print(gg.proxy_getter_functions)
  54. print(gg.host_ip)
  55. print(gg.host_port)
  56. print(gg.db_password)