123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import uuid
- import os
- import platform
- def getConnectionStr(connstr, index):
- str = connstr[index]
- strlist = str.split("=")
- return strlist[1].replace("'", "")
- # 获取系统默认下载路径
- def get_download_dir():
- if platform.system() == "Windows":
- return os.path.join(os.path.expanduser("~"), "Downloads")
- elif platform.system() == "Darwin":
- return os.path.join(os.path.expanduser("~"), "Downloads")
- elif platform.system() == "Linux":
- return os.path.join(os.path.expanduser("~"), "Downloads")
- else:
- return None
- def get_temp_dir():
- return f'D:/temp'
- # dict转换str 并进行拼接
- def dict_to_str_with_equals(d):
- # 使用列表推导式生成键值对字符串列表
- pairs = [f"{key}='{value}'" for key, value in d.items()]
- # 使用 join 方法将列表中的字符串合并为一个字符串
- return ' '.join(pairs)
- # postgis数据库连接转字符串
- def sourceToDBConfig(source):
- result = {
- "mode": 2
- }
- arr = source.split(" ")
- for attr in arr:
- if attr.__contains__("srid") or attr.__contains__("sslmode"):
- continue
- if attr.__contains__("="):
- cur = attr.split("=")
- key = cur[0].replace("'", "")
- value = cur[1].replace("'", "").replace("\"", "")
- if key == "table":
- result[key] = value.split(".")[1]
- result["schema"] = value.split(".")[0]
- else:
- result[key] = value
- return result
- # 获取UUID
- def getUUID():
- id = uuid.uuid4().__str__()
- id = id.replace("-", "")
- return id
|