Update public source
This commit is contained in:
+13
-3
@@ -2,9 +2,19 @@
|
|||||||
Centralized map service configuration.
|
Centralized map service configuration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
MAP_STYLE_URL = (
|
import sys
|
||||||
"http://127.0.0.1:8080/styles/server-map/style.json"
|
from pathlib import Path
|
||||||
)
|
|
||||||
|
|
||||||
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
if str(PROJECT_ROOT) not in sys.path:
|
||||||
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
|
from src.tileserver_config import load_tileserver_config
|
||||||
|
|
||||||
|
|
||||||
|
MAP_STYLE_URL = load_tileserver_config(PROJECT_ROOT)["style_url"]
|
||||||
|
|
||||||
|
|
||||||
def get_map_style_url():
|
def get_map_style_url():
|
||||||
|
|||||||
+14
-29
@@ -16,40 +16,25 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
if str(PROJECT_ROOT) not in sys.path:
|
||||||
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
|
from tileserver_config import load_tileserver_config
|
||||||
|
|
||||||
|
TILESERVER_CONFIG_DATA = load_tileserver_config(PROJECT_ROOT)
|
||||||
|
|
||||||
UNIT_NAME = "wifi-gps-mapper"
|
UNIT_NAME = "wifi-gps-mapper"
|
||||||
APP_HOST = "127.0.0.1"
|
APP_HOST = "127.0.0.1"
|
||||||
APP_PORT = 5000
|
APP_PORT = 5000
|
||||||
TILE_HOST = "127.0.0.1"
|
|
||||||
TILE_PORT = int(os.environ.get("WIFI_GPS_TILESERVER_PORT", "8080"))
|
|
||||||
TILE_STYLE_URL = (
|
|
||||||
f"http://{TILE_HOST}:{TILE_PORT}"
|
|
||||||
"/styles/server-map/style.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
TILESERVER_DIR = Path(
|
TILE_HOST = TILESERVER_CONFIG_DATA["host"]
|
||||||
os.environ.get(
|
TILE_PORT = TILESERVER_CONFIG_DATA["port"]
|
||||||
"WIFI_GPS_TILESERVER_DIR",
|
TILE_STYLE_URL = TILESERVER_CONFIG_DATA["style_url"]
|
||||||
str(Path.home() / "Projects" / "server-map")
|
|
||||||
)
|
|
||||||
).expanduser()
|
|
||||||
|
|
||||||
TILESERVER_ENTRY = Path(
|
TILESERVER_DIR = TILESERVER_CONFIG_DATA["directory"]
|
||||||
os.environ.get(
|
TILESERVER_ENTRY = TILESERVER_CONFIG_DATA["entry"]
|
||||||
"WIFI_GPS_TILESERVER_ENTRY",
|
TILESERVER_CONFIG = TILESERVER_CONFIG_DATA["config"]
|
||||||
str(
|
|
||||||
TILESERVER_DIR
|
|
||||||
/ "node_modules"
|
|
||||||
/ "tileserver-gl-light"
|
|
||||||
/ "src"
|
|
||||||
/ "main.js"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).expanduser()
|
|
||||||
|
|
||||||
TILESERVER_CONFIG = os.environ.get(
|
|
||||||
"WIFI_GPS_TILESERVER_CONFIG",
|
|
||||||
"config.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
STARTUP_TIMEOUT = 30
|
STARTUP_TIMEOUT = 30
|
||||||
POLL_INTERVAL = 0.5
|
POLL_INTERVAL = 0.5
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
"""
|
||||||
|
Shared TileServer configuration loader.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_ENTRY = "node_modules/tileserver-gl-light/src/main.js"
|
||||||
|
DEFAULT_CONFIG = "config.json"
|
||||||
|
DEFAULT_STYLE = "server-map"
|
||||||
|
|
||||||
|
|
||||||
|
def load_tileserver_config(project_root):
|
||||||
|
project_root = Path(project_root).expanduser().resolve()
|
||||||
|
config_file = project_root / "config" / "config.yaml"
|
||||||
|
|
||||||
|
try:
|
||||||
|
with config_file.open("r", encoding="utf-8") as file:
|
||||||
|
application_config = yaml.safe_load(file) or {}
|
||||||
|
except (OSError, yaml.YAMLError) as error:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Не удалось загрузить конфигурацию {config_file}: {error}"
|
||||||
|
) from error
|
||||||
|
|
||||||
|
if not isinstance(application_config, dict):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Корень config/config.yaml должен быть YAML-объектом."
|
||||||
|
)
|
||||||
|
|
||||||
|
section = application_config.get("tileserver", {})
|
||||||
|
|
||||||
|
if not isinstance(section, dict):
|
||||||
|
raise RuntimeError(
|
||||||
|
"Раздел tileserver в config/config.yaml должен быть YAML-объектом."
|
||||||
|
)
|
||||||
|
|
||||||
|
directory_value = os.environ.get(
|
||||||
|
"WIFI_GPS_TILESERVER_DIR",
|
||||||
|
section.get("directory", "map-server")
|
||||||
|
)
|
||||||
|
|
||||||
|
directory = Path(directory_value).expanduser()
|
||||||
|
|
||||||
|
if "WIFI_GPS_TILESERVER_DIR" not in os.environ and not directory.is_absolute():
|
||||||
|
directory = project_root / directory
|
||||||
|
|
||||||
|
directory = directory.resolve()
|
||||||
|
|
||||||
|
entry_from_environment = "WIFI_GPS_TILESERVER_ENTRY" in os.environ
|
||||||
|
entry_value = os.environ.get(
|
||||||
|
"WIFI_GPS_TILESERVER_ENTRY",
|
||||||
|
section.get("entry", DEFAULT_ENTRY)
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = Path(entry_value).expanduser()
|
||||||
|
|
||||||
|
if not entry.is_absolute() and not entry_from_environment:
|
||||||
|
entry = directory / entry
|
||||||
|
|
||||||
|
config_value = os.environ.get(
|
||||||
|
"WIFI_GPS_TILESERVER_CONFIG",
|
||||||
|
section.get("config", DEFAULT_CONFIG)
|
||||||
|
)
|
||||||
|
|
||||||
|
config = Path(config_value).expanduser()
|
||||||
|
config_path = config if config.is_absolute() else directory / config
|
||||||
|
|
||||||
|
host = str(section.get("host", "127.0.0.1")).strip()
|
||||||
|
|
||||||
|
try:
|
||||||
|
port = int(
|
||||||
|
os.environ.get(
|
||||||
|
"WIFI_GPS_TILESERVER_PORT",
|
||||||
|
section.get("port", 8080)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except (TypeError, ValueError) as error:
|
||||||
|
raise RuntimeError("Некорректный порт TileServer.") from error
|
||||||
|
|
||||||
|
if not host:
|
||||||
|
raise RuntimeError("Не задан host для TileServer.")
|
||||||
|
|
||||||
|
if not 1 <= port <= 65535:
|
||||||
|
raise RuntimeError(f"Некорректный порт TileServer: {port}")
|
||||||
|
|
||||||
|
style = str(section.get("style", DEFAULT_STYLE)).strip().strip("/")
|
||||||
|
|
||||||
|
if not style:
|
||||||
|
raise RuntimeError("Не задан style для TileServer.")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"host": host,
|
||||||
|
"port": port,
|
||||||
|
"directory": directory,
|
||||||
|
"entry": entry,
|
||||||
|
"config": str(config),
|
||||||
|
"config_path": config_path,
|
||||||
|
"style": style,
|
||||||
|
"style_url": (
|
||||||
|
f"http://{host}:{port}/styles/{style}/style.json"
|
||||||
|
),
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user