import configparser from pathlib import Path from os import path class Config: def __init__(self, application_basedir, devicename, port, host): self.application_basedir = application_basedir self.devicename = devicename self.port = port self.host = host self.current_volume = 0.6 @staticmethod def load(filepath): c = configparser.ConfigParser() try: c.read(path.expanduser(filepath)) application_basedir = path.expanduser( c.get("General", "application_basedir") ) host = c.get("Network", "host") port = c.get("Network", "port") devicename = c.get("Audio", "device_name") # Create directory if it doesn't exist # along with the sounds directory Path(application_basedir).mkdir(parents=True, exist_ok=True) Path(f"{application_basedir}/sounds").mkdir(parents=True, exist_ok=True) config = Config(application_basedir, devicename, port, host) return config except Exception as e: print(e) return None