-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
27 lines (21 loc) · 827 Bytes
/
Copy pathsettings.py
File metadata and controls
27 lines (21 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
settings.py — сохранение/загрузка настроек программы между запусками
(пути к папкам SRTM/кэша карт, пороги анализа, язык, зум, провайдер карты
и т.п.) в простой JSON-файл рядом с программой.
"""
from __future__ import annotations
import json
from pathlib import Path
def load_settings(path: str) -> dict:
p = Path(path)
if not p.is_file():
return {}
try:
return json.loads(p.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return {}
def save_settings(path: str, data: dict) -> None:
try:
Path(path).write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
except OSError:
pass