Source code for gfinder.config
"""Config module."""
import yaml
from pathlib import Path
# Set default parameters
DEFAULT_N_STEPS = 100
DEFAULT_TIME_STEP = 1.0 # second
MAX_N_STEPS = 1000
[docs]class Config:
def __init__(self):
config_file = Path.home() / '.gfinder_config.yml'
# Set default required configuration variables/values
self.kernels_dir = str(Path.home() / 'spice_kernels/juice/kernels') # '/srv/spice_kernels/juice/kernels'
self.app_data_dir = str(Path.home() / 'gfinder-data') # '/srv/gfinder-data'
self.user_data_dir = str(Path.home() / 'data')
self.default_mission_scenario_id = 'CREMA50'
# Read configuration variables from config file if exists.
if config_file.exists():
with open(config_file, 'r') as stream:
config_dict = yaml.safe_load(stream)
required_keys = ['kernels_dir', 'app_data_dir', 'user_data_dir', 'default_mission_scenario_id']
for required_key in required_keys:
if required_key in config_dict.keys():
setattr(self, required_key, config_dict[required_key])
else:
print(f'Missing {required_key} variable in {config_file} config file.')
else:
# Create config file with default values, if it does not exist.
with open(config_file, 'w') as stream:
config_dict = self.__dict__
yaml.dump(config_dict, stream, default_flow_style=False)
[docs] def set(self):
#TODO: built-in ConfigParser could be used
pass
def __repr__(self):
return '<%s %r>' % (self.__class__.__name__, self.__dict__)