StringUtils.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import uuid
  2. import os
  3. import platform
  4. def getConnectionStr(connstr, index):
  5. str = connstr[index]
  6. strlist = str.split("=")
  7. return strlist[1].replace("'", "")
  8. # 获取系统默认下载路径
  9. def get_download_dir():
  10. if platform.system() == "Windows":
  11. return os.path.join(os.path.expanduser("~"), "Downloads")
  12. elif platform.system() == "Darwin":
  13. return os.path.join(os.path.expanduser("~"), "Downloads")
  14. elif platform.system() == "Linux":
  15. return os.path.join(os.path.expanduser("~"), "Downloads")
  16. else:
  17. return None
  18. def get_temp_dir():
  19. return f'D:/temp'
  20. # dict转换str 并进行拼接
  21. def dict_to_str_with_equals(d):
  22. # 使用列表推导式生成键值对字符串列表
  23. pairs = [f"{key}='{value}'" for key, value in d.items()]
  24. # 使用 join 方法将列表中的字符串合并为一个字符串
  25. return ' '.join(pairs)
  26. # postgis数据库连接转字符串
  27. def sourceToDBConfig(source):
  28. result = {
  29. "mode": 2
  30. }
  31. arr = source.split(" ")
  32. for attr in arr:
  33. if attr.__contains__("srid") or attr.__contains__("sslmode"):
  34. continue
  35. if attr.__contains__("="):
  36. cur = attr.split("=")
  37. key = cur[0].replace("'", "")
  38. value = cur[1].replace("'", "").replace("\"", "")
  39. if key == "table":
  40. result[key] = value.split(".")[1]
  41. result["schema"] = value.split(".")[0]
  42. else:
  43. result[key] = value
  44. return result
  45. # 获取UUID
  46. def getUUID():
  47. id = uuid.uuid4().__str__()
  48. id = id.replace("-", "")
  49. return id