def parse_config()

in python/lookerstudio/lookerstudio_deployment.py [0:0]


def parse_config(config_file:str) -> list:
    """ Parses config file and returns a list of dicts for the data sources. """
    try:
        # ExtendedInterpolation to parse ${} format in config file
        config = ConfigParser(interpolation=ExtendedInterpolation())
        
        # optionxform to preserve case
        config.optionxform = str
        config.read(config_file)
            
        sections = config.sections()
        sources = list()

        for section in sections:
            # Do not add COMMON section to collection of options
            if section == "COMMON":
                continue
            # Convert options for the section to dict
            options = dict(config.items(section))
            # Format section name for URL and add to options dict
            section = section.replace(' ','%20')
            options.update(dict(datasourceName=section))
            sources.append(options)
        return sources
    # Handle exception from ConfigParser and exit program with error
    except ConfigError as error:
        print(f'Error parsing file {CONFIG_FILE}.\n{error}')
        sys.exit(1)