GetConfig.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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()
  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 proxy_getter_functions(self):
  41. return self.config_file.options('ProxyGetter')
  42. if __name__ == '__main__':
  43. gg = GetConfig()
  44. print(gg.db_type)
  45. print(gg.db_name)
  46. print(gg.db_host)
  47. print(gg.db_port)
  48. print(gg.proxy_getter_functions)