def get(cls, key, alt=None): if not cls._loaded: raise RuntimeError("Attempting to access SettingsManager " "before it has been loaded.") checksum = Tools.checksum_file(cls._settings_file) if checksum != cls._checksum: cls.load_settings() return cls._parameters.get(key) or alt
def load_settings(cls, settings_file=DEFAULT_SETTINGS_PATH, reloading=False): loaded = False # load yaml settings file path = cls._settings_file = os.environ.get(ENV.settings, None) if path is None: path = cls._settings_file = os.path.join(os.path.dirname(__file__), settings_file) checksum = Tools.checksum_file(path) if reloading or checksum != cls._checksum: for i in range(1, MAX_REGEX + 1): cls._parameters["fileRegex%i" % i] = dict() with open(path, "r") as file_: settings = yaml.safe_load(file_) # TODO implement value check # TODO check if interger for port value # TODO check if diffFileName has been defined # TODO should be better than this hack exceptions = ["fileregex%i" % i for i in range(1, MAX_REGEX + 1)] settings = compact_dict(settings, exceptions=exceptions) # set up with class variables for key in cls._parameters.keys(): for set_key, value in settings.items(): if set_key.lower() == key.lower() and value is not None: cls._parameters[key] = value cls._parameters = dict(cls._parameters) cls._loaded = loaded = True cls._checksum = checksum return loaded