from pathlib import Path import os, json class Config: CONF_DIR=os.path.join(os.environ['HOME'],".clusterman/") CONF_FILE=os.path.join(CONF_DIR,"clusterman.json") def __init__(self): Path(self.CONF_DIR).mkdir(parents=True, exist_ok=True) self.load() def load(self): self.config={"example":None} if os.path.exists(self.CONF_FILE): with open(self.CONF_FILE) as f: self.config=json.load(f) else: self.save() def save(self): with open(self.CONF_FILE, "w") as f: f.write(json.dumps(self.config)) def __getitem__(self, key): return self.config[key]