GetConfig.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. import ConfigParser
  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 = ConfigParser.ConfigParser()
  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. if __name__ == '__main__':
  39. gg = GetConfig()
  40. print gg.db_type
  41. print gg.db_name
  42. print gg.db_host
  43. print gg.db_port