conf_reader.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys
  2. import os
  3. import re
  4. abspath = os.path.abspath(__file__)
  5. root_path = re.sub(r"tendata-warehouse.*", "tendata-warehouse", abspath)
  6. sys.path.append(root_path)
  7. import json
  8. from configparser import ConfigParser
  9. import yaml
  10. from dw_base.scheduler.mg2es.path_util import PathUtil
  11. class ConfReader():
  12. def get_yml_data(self, yml_file_path):
  13. with open(yml_file_path, 'r') as file:
  14. data = yaml.safe_load(file)
  15. return data
  16. def get_json_data(self, json_file_path):
  17. with open(json_file_path) as f:
  18. data = json.load(f)
  19. return data
  20. def get_es_conf(self):
  21. path = PathUtil.get_es_conn_path()
  22. print(path)
  23. config_parser = ConfigParser()
  24. config_parser.read(path)
  25. host = config_parser.get('base', 'host')
  26. port = int(config_parser.get('base', 'port'))
  27. return host, port
  28. def get_redis_conf(self):
  29. path = PathUtil.get_redis_conn_path()
  30. print(path)
  31. config_parser = ConfigParser()
  32. config_parser.read(path)
  33. host = config_parser.get('base', 'host')
  34. port = int(config_parser.get('base', 'port'))
  35. db = int(config_parser.get('base', 'db'))
  36. password = config_parser.get('base', 'password')
  37. # 将空字符串密码转换为 None
  38. password = password if password != '' else None
  39. return host, port,db, password
  40. if __name__ == '__main__':
  41. cf = ConfReader()
  42. print(cf.get_es_conf())
  43. print(cf.get_redis_conf())