-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_paths.py
More file actions
39 lines (28 loc) · 1008 Bytes
/
Copy pathruntime_paths.py
File metadata and controls
39 lines (28 loc) · 1008 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
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations
import os
import sys
from pathlib import Path
APP_NAME = "Turnlight"
SOURCE_DIR = Path(__file__).resolve().parent
def is_frozen() -> bool:
return bool(getattr(sys, "frozen", False))
def app_base_dir() -> Path:
bundled_dir = getattr(sys, "_MEIPASS", None)
if bundled_dir:
return Path(str(bundled_dir)).resolve()
if is_frozen():
return Path(sys.executable).resolve().parent
return SOURCE_DIR
def user_data_dir() -> Path:
if not is_frozen():
return SOURCE_DIR
local_app_data = os.environ.get("LOCALAPPDATA")
if local_app_data:
return Path(local_app_data) / APP_NAME
return Path.home() / "AppData" / "Local" / APP_NAME
def ensure_user_data_dirs() -> None:
data_dir = user_data_dir()
data_dir.mkdir(parents=True, exist_ok=True)
samples_dir = data_dir / "samples"
for state in ("busy_stop", "typing_arrow", "ignored"):
(samples_dir / state).mkdir(parents=True, exist_ok=True)