45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
import pathlib
|
|
import appdirs
|
|
import yaml
|
|
from collections import namedtuple
|
|
|
|
config_dir = pathlib.Path(appdirs.user_config_dir("ED_LRR"))
|
|
config_dir.mkdir(parents=True, exist_ok=True)
|
|
config_file = config_dir / "config.yml"
|
|
config_file.touch()
|
|
|
|
data_dir = pathlib.Path(appdirs.user_data_dir("ED_LRR"))
|
|
data_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def make_config():
|
|
return {
|
|
"history_bodies_url": [],
|
|
"history_systems_url": [],
|
|
"history_bodies_path": [],
|
|
"history_systems_path": [],
|
|
"history_out_path": [],
|
|
"range": None,
|
|
"primary": False,
|
|
"mode": "bfs",
|
|
"greedyness": 0.5,
|
|
}
|
|
|
|
|
|
def write(cfg):
|
|
with config_file.open("w", encoding="utf-8") as of:
|
|
yaml.dump(cfg._asdict(), of, default_flow_style=False)
|
|
|
|
|
|
def load():
|
|
data = yaml.load(config_file.open(encoding="utf-8"), Loader=yaml.Loader)
|
|
if data is None:
|
|
data = make_config()
|
|
write(data)
|
|
|
|
return namedtuple("Config", data)(**data)
|
|
|
|
|
|
# print("CFG:", yaml.load_config())
|
|
# print(config_file, data_dir)
|
|
# exit(1)
|