-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathversion_util.py
More file actions
29 lines (22 loc) · 828 Bytes
/
version_util.py
File metadata and controls
29 lines (22 loc) · 828 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
28
29
import os
import json
def read_version(default: str = "v1.0.0") -> str:
env_ver = os.getenv("WATCHGUARD_VERSION")
if env_ver and isinstance(env_ver, str) and env_ver.strip():
return env_ver.strip()
settings_paths = [
os.path.join(os.getcwd(), "settings.json"),
os.path.join(os.path.dirname(__file__), "settings.json"),
]
for path in settings_paths:
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
ver = data.get("version") if isinstance(data, dict) else None
if isinstance(ver, str) and ver.strip():
return ver.strip()
except Exception:
pass
return default
APP_VERSION = read_version()