Coverage for / opt / hostedtoolcache / Python / 3.10.20 / x64 / lib / python3.10 / site-packages / starlord / _config.py: 67%
30 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 15:47 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 15:47 +0000
1import os
2import platform
3from collections import namedtuple
4from pathlib import Path
5from types import SimpleNamespace
7__version__ = "0.2.3"
9_TextFormatCodes_ = namedtuple(
10 "_TextFormatCodes_",
11 ['end', 'bold', 'underline', 'blue', 'yellow', 'red', 'green'],
12)
14config = SimpleNamespace(
15 system=platform.system(),
16 base_dir=Path.home() / ".starlord",
17 cache_dir=Path.home() / ".starlord" / "cycache",
18 grid_dir=Path.home() / ".starlord" / "grids",
19 text_format=_TextFormatCodes_(*[f"\033[{i}m" for i in [0, 1, 4, 34, 33, 31, 32]]),
20 text_format_off=_TextFormatCodes_("", "", "", "", "", "", ""),
21)
24def _load_config():
25 config.system = platform.system()
26 if "STARLORD_DATA_DIR" in os.environ.keys():
27 config.base_dir = Path(os.environ['STARLORD_DATA_DIR'])
28 assert config.base_dir.parent.exists()
29 config.base_dir.mkdir(exist_ok=True)
30 elif config.system == "Linux":
31 assert Path.home().exists()
32 config.base_dir = Path.home() / ".config" / "starlord"
33 config.base_dir.mkdir(parents=True, exist_ok=True)
34 elif config.system == "Darwin":
35 assert Path.home().exists()
36 config.base_dir = Path.home() / "Library" / "Application Support" / "starlord"
37 config.base_dir.mkdir(parents=True, exist_ok=True)
38 else:
39 assert Path.home().exists()
40 config.base_dir = Path.home() / ".starlord"
41 config.base_dir.mkdir(parents=True, exist_ok=True)
42 config.cache_dir = config.base_dir / "cycache"
43 config.cache_dir.mkdir(exist_ok=True)
44 config.grid_dir = config.base_dir / "grids"
45 config.grid_dir.mkdir(exist_ok=True)
48_load_config()