diff --git a/ed_lrr_gui/config.py b/ed_lrr_gui/config.py index 9720f2d..6bf3d79 100644 --- a/ed_lrr_gui/config.py +++ b/ed_lrr_gui/config.py @@ -1,46 +1,46 @@ import pathlib from collections import namedtuple - +import profig import appdirs -import yaml +import os -config_dir = pathlib.Path(appdirs.user_config_dir("ED_LRR")) +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 = config_dir / "config.ini" config_file.touch() -data_dir = pathlib.Path(appdirs.user_data_dir("ED_LRR")) -data_dir.mkdir(parents=True, exist_ok=True) +cfg = profig.Config(str(config_file), strict=True) +cfg.init("history.bodies_url", [], "path_list", comment="history of bodies.json urls") +cfg.init("history.systems_url", [], "path_list", comment="history of systems.json urls") +cfg.init( + "history.bodies_path", + [], + "path_list", + comment="history of bodies.json download paths", +) +cfg.init( + "history.systems_path", + [], + "path_list", + comment="history of systems.json download paths", +) +cfg.init( + "history.out_path", + [], + "path_list", + comment="history of output paths (stars.csv and precomputed graphs)", +) +cfg.init("route.range", 7.56, comment="jump range") +cfg.init("route.primary", False, comment="only route through primary stars") +cfg.init("route.mode", "bfs", comment="routing mode") +cfg.init( + "route.prune.min_improvement", + 10.0, + comment="path needs to improve by at least (jump_range*min_improvement) in route.prune.steps", +) +cfg.init("route.prune.steps", 5, comment="number of steps before path gets pruned") +cfg.init("route.greediness", 0.5, comment="A* greediness") +cfg.init("folders.data_dir", os.path.join(config_dir, "data"), comment="Data directory") -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) +cfg.sync()