read.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import yaml
  2. topoCheckData = None
  3. # 读取yaml
  4. def read_yaml_file(filepath):
  5. with open(filepath, 'r') as file:
  6. data = yaml.load(file, Loader=yaml.FullLoader)
  7. return data
  8. # 调用示例
  9. topoCheckData = read_yaml_file(
  10. "D:\\Program Files\\QGIS 3.34.9\\apps\\qgis-ltr\\python\\plugins\\processing\\tools\\topology\\topoCheck.yaml")
  11. print(topoCheckData)
  12. print(topoCheckData["topoCheck"]["A03"])
  13. def getTopoCheckSQL(type, my_dict):
  14. # sqllist = []
  15. data = topoCheckData["topoCheck"][type]
  16. tempSql = data["ALG"]
  17. for key in my_dict:
  18. value = my_dict[key]
  19. k = f"@{key}@"
  20. tempSql = tempSql.replace(k, value)
  21. return tempSql
  22. #获取description
  23. def getTopoCheckDescription(type):
  24. # sqllist = []
  25. data = topoCheckData["topoCheck"][type]
  26. description = data["UI"]["description"]
  27. return description
  28. #获取note
  29. def getTopoCheckNote(type):
  30. # sqllist = []
  31. data = topoCheckData["topoCheck"][type]
  32. note = data["note"]
  33. return note
  34. # my_dict = {
  35. # "intable_s": "topology_table",
  36. # "outtable": "topology_table_temp"
  37. # }
  38. # sql = getTopoCheckSQL("A03", my_dict)
  39. # print(sql)
  40. # for s in sql.split(";"):
  41. # print(s)