def set_application_config_file(configuration_file): """ This method sets the application wide configuration file that will be used :param configuration_file: config file name if the file is in the default configuration path or path to the configuration file if it is not. :return: no return value :exception: ConfigException is raised if there already is a configuration file set """ global __configuration_file_name if __configuration_file_name is not None: raise AppConfigException( "Configuration file can't be changed once an initial configuartion file has been provided") __configuration_file_name = configuration_file
def read_config_from_file(configuration_file): """ Given a file name or absolute path, read its configuration information in json format and return its object representation :param configuration_file: file name or absolute path for the file that contains the configuration information :return: an object representation of the json formatted configuration information read from the file """ if (configuration_file is None): # If there is no configuration file, we return an empty configuration object return {} config_file_path = configuration_file if not os.path.isabs(config_file_path): config_file_path = os.path.join(_folder_config, configuration_file) try: return general.read_json(config_file_path) except Exception as e: msg = "Config file {} could not be read, because {}".format(config_file_path, str(e)) raise AppConfigException(msg)