feat(config): Update config system to use profig
This commit is contained in:
		
							parent
							
								
									fb3a13037c
								
							
						
					
					
						commit
						b1143c3510
					
				
					 1 changed files with 37 additions and 37 deletions
				
			
		|  | @ -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() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue