def load(self, filename, verify_version=True): """Loads a YAML file from disk. Args: filename: The file to load. verify_version: Boolean which specifies whether this method should verify whether this file's config_version is compatible with this version of MPF. Default is True. Returns: A dictionary of the settings from this YAML file. """ config = Util.keys_to_lower( self.byteify(json.load(open(filename, 'r')))) # if verify_version: # self.check_config_file_version(filename) # # try: # self.log.debug("Loading configuration file: %s", filename) # config = Util.keys_to_lower(json.loads(open(filename, 'r'))) # except yaml.YAMLError, exc: # if hasattr(exc, 'problem_mark'): # mark = exc.problem_mark # self.log.critical("Error found in config file %s. Line %s, " # "Position %s", filename, mark.line+1, # mark.column+1) # sys.exit() # except: # self.log.critical("Couldn't load from file: %s", filename) # raise return config
def load(self, filename, verify_version=True): """Loads a YAML file from disk. Args: filename: The file to load. verify_version: Boolean which specifies whether this method should verify whether this file's config_version is compatible with this version of MPF. Default is True. Returns: A dictionary of the settings from this YAML file. """ config = Util.keys_to_lower(self.byteify(json.load(open(filename, 'r')))) # if verify_version: # self.check_config_file_version(filename) # # try: # self.log.debug("Loading configuration file: %s", filename) # config = Util.keys_to_lower(json.loads(open(filename, 'r'))) # except yaml.YAMLError, exc: # if hasattr(exc, 'problem_mark'): # mark = exc.problem_mark # self.log.critical("Error found in config file %s. Line %s, " # "Position %s", filename, mark.line+1, # mark.column+1) # sys.exit() # except: # self.log.critical("Couldn't load from file: %s", filename) # raise return config
def load(self, filename, verify_version=True, halt_on_error=False): """Loads a YAML file from disk. Args: filename: The file to load. verify_version: Boolean which specifies whether this method should verify whether this file's config_version is compatible with this version of MPF. Default is True. halt_on_error: Boolean which controls what happens if the file can't be loaded. (Not found, invalid format, etc. If True, MPF will raise an error and exit. If False, an empty config dictionary will be returned. Returns: A dictionary of the settings from this YAML file. """ if verify_version and not Config.check_config_file_version(filename): raise Exception("Config file version mismatch: {}". format(filename)) try: self.log.debug("Loading configuration file: %s", filename) with open(filename, 'r') as f: config = Util.keys_to_lower(yaml.load(f)) except yaml.YAMLError, exc: if hasattr(exc, 'problem_mark'): mark = exc.problem_mark self.log.critical("Error found in config file %s. Line %s, " "Position %s", filename, mark.line+1, mark.column+1) if halt_on_error: sys.exit() else: config = dict()
def load(self, filename, verify_version=True, halt_on_error=False): """Loads a YAML file from disk. Args: filename: The file to load. verify_version: Boolean which specifies whether this method should verify whether this file's config_version is compatible with this version of MPF. Default is True. halt_on_error: Boolean which controls what happens if the file can't be loaded. (Not found, invalid format, etc. If True, MPF will raise an error and exit. If False, an empty config dictionary will be returned. Returns: A dictionary of the settings from this YAML file. """ if verify_version and not Config.check_config_file_version(filename): raise Exception( "Config file version mismatch: {}".format(filename)) try: self.log.debug("Loading configuration file: %s", filename) with open(filename, 'r') as f: config = Util.keys_to_lower(yaml.load(f)) except yaml.YAMLError, exc: if hasattr(exc, 'problem_mark'): mark = exc.problem_mark self.log.critical( "Error found in config file %s. Line %s, " "Position %s", filename, mark.line + 1, mark.column + 1) if halt_on_error: sys.exit() else: config = dict()