Skip to content

Commit

Permalink
feat: all cache and db_profiles are stored in yuheng path
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoshuBaby committed Mar 2, 2024
1 parent 5886a7e commit edaf412
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/yuheng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
YUHENG_PATH,
YUHENG_START_ID,
YUHENG_VERSION,
get_yuheng_path,
)
from .basic.model import BaseOsmModel
from .component.type_constraint import Bounds, Member
Expand Down Expand Up @@ -217,7 +218,9 @@ def worker(work_url: str, allow_cache: bool) -> str:
print("cache file: ", url_cache_filename)

with open(
os.path.join(YUHENG_PATH, "cache", url_cache_filename),
os.path.join(
get_yuheng_path(), "cache", url_cache_filename
),
"w",
encoding="utf-8",
) as f_cache:
Expand Down
16 changes: 12 additions & 4 deletions src/yuheng/basic/global_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ def get_ua() -> str:


def get_yuheng_path() -> str:
def init_yuheng_path():
pass

return ""
def init_yuheng_path() -> None:
YUHENG_FOLDER = ["cache", "db_profiles"]
if os.path.exists(YUHENG_PATH) != True:
print(YUHENG_PATH, "isn't exist!")
os.mkdir(YUHENG_PATH)
for folder in YUHENG_FOLDER:
if os.path.exists(os.path.join(YUHENG_PATH, folder)) != True:
print(os.path.join(YUHENG_PATH, folder), "isn't exist!")
os.mkdir(os.path.join(YUHENG_PATH, folder))

init_yuheng_path()
return YUHENG_PATH
9 changes: 4 additions & 5 deletions src/yuheng/method/network.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
network 模块并不负责从网上读取数据,它负责的是endpoint和各种网络相关环境的处理。而从网络上读取数据是作为read driver的一种(因为并不仅仅有一种来源的driver)
"""
from typing import Optional

from ..basic import YUHENG_CORE_NAME, YUHENG_VERSION

# from src.yuheng.basic.global_const import YUHENG_CORE_NAME, YUHENG_VERSION

# network 模块并不负责从网上读取数据,它负责的是endpoint和各种网络相关环境的处理。而从网络上读取数据是作为read driver的一种(因为并不仅仅有一种来源的driver)
from ..basic import YUHENG_CORE_NAME, YUHENG_VERSION, get_ua


def get_endpoint_api(endpoint_name="osm", property="url") -> Optional[str]:
Expand Down
18 changes: 14 additions & 4 deletions src/yuheng/plugin/driver_db_mysql/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import json
import os
import sys

import pymysql

database_profile_path = os.path.join(
YUHENG_PATH, "db_profiles", "mysql.db_profiles.yuheng"
)
current_dir = os.path.dirname(os.path.realpath(__file__))
src_dir = os.path.join(current_dir, "..", "..", "..")
sys.path.append(src_dir)
from yuheng import Carto
from yuheng.basic import get_yuheng_path

database_profile = json.load(
open(database_profile_path, "r", encoding="utf-8")
open(
os.path.join(
get_yuheng_path(), "db_profiles", "mysql.db_profiles.yuheng"
),
"r",
encoding="utf-8",
)
)

connection = pymysql.connect(
Expand Down
13 changes: 9 additions & 4 deletions src/yuheng/plugin/driver_db_postgresql/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import sys
from typing import Any, Dict, List, Optional, Tuple
Expand All @@ -12,13 +13,17 @@
src_dir = os.path.join(current_dir, "..", "..", "..")
sys.path.append(src_dir)
from yuheng import Carto
from yuheng.basic import get_yuheng_path
from yuheng.component import Node, Way

database_profile_path = os.path.join(
YUHENG_PATH, "db_profiles", "postgresql.db_profiles.yuheng"
)
database_profile = json.load(
open(database_profile_path, "r", encoding="utf-8")
open(
os.path.join(
get_yuheng_path(), "db_profiles", "postgresql.db_profiles.yuheng"
),
"r",
encoding="utf-8",
)
)

PROJ_TRANSFORMER = pyproj.Transformer.from_crs("epsg:3857", "epsg:4326")
Expand Down

0 comments on commit edaf412

Please sign in to comment.