ConfigUtils.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import xml.etree.ElementTree as ET
  2. #读取xml文件
  3. class ConfigUtils():
  4. def __init__(self,file):
  5. self.url = ""
  6. self.tree = ET.parse(file)
  7. self.root = self.tree.getroot()
  8. def readTop(self, key, child):
  9. datas = []
  10. data = self.root.find(key)
  11. for key in child:
  12. datas.append(data.get(key))
  13. return datas
  14. def readTopDict(self, key, child):
  15. datas = {}
  16. data = self.root.find(key)
  17. for key in child:
  18. datas[key] = data.get(key)
  19. return datas
  20. def readConfig(self,parent,child):
  21. datas=[]
  22. for childLine in self.root.find(parent):
  23. data=[]
  24. for key in child:
  25. data.append(childLine.get(key))
  26. datas.append(data)
  27. return datas
  28. def readConfigDict(self,parent,child):
  29. datas=[]
  30. for childLine in self.root.find(parent):
  31. data={}
  32. for key in child:
  33. data[key]=childLine.get(key)
  34. datas.append(data)
  35. return datas
  36. def readConfigSingle(self,key):
  37. data = self.root.find(key).text
  38. return data
  39. if __name__ == '__main__':
  40. config = ConfigUtils("logger.conf")