def config_read_data()

in plugins/asfdata.py [0:0]


def config_read_data(pel_ob):
    print('-----\nasfdata')

    asf_data = pel_ob.settings.get('ASF_DATA')

    if not asf_data:
        print('This Pelican installation is not using ASF_DATA')
        return

    debug = asf_data['debug']

    if debug:
        for key in asf_data:
            print(f'config: [{key}] = {asf_data[key]}')

    # This must be present in ASF_DATA. It contains data for use
    # by our plugins, and possibly where we load/inject data from
    # other sources.
    metadata = asf_data['metadata']

    # Lift data from ASF_DATA['data'] into METADATA
    if 'data' in asf_data:
        if debug:
            print(f'Processing {asf_data["data"]}')
        config_data = read_config(asf_data['data'], debug)
        for key in config_data:
            # first check for data that is a singleton with special handling
            if key == 'eccn':
                # process eccn data
                fname = config_data[key]['file']
                metadata[key] = v = process_eccn(fname, debug)
                if debug:
                    print('ECCN V:', v)
                continue

            if key == 'twitter':
                # process twitter data
                # if we decide to have multiple twitter feeds available then move next to blog below
                handle = config_data[key]['handle']
                count = config_data[key]['count']
                metadata[key] = v = process_twitter(handle, count, debug)
                if debug:
                    print('TWITTER V:', v)
                continue

            value = config_data[key]
            if isinstance(value, dict):
                # dictionaries may have multiple data structures that are processed with a sequence of actions
                # into multiple sequences and dictionaries.
                if debug:
                    print(f'-----\n{key} creates one or more sequences')
                    print(value)
                # special cases that are multiple are processed first
                if 'blog' in value:
                    # process blog feed
                    feed = config_data[key]['blog']
                    count = config_data[key]['count']
                    if 'content' in config_data[key].keys():
                        words = config_data[key]['content']
                    else:
                        words = None
                    metadata[key] = v = process_blog(feed, count, words, debug)
                    if debug:
                        print('BLOG V:', v)
                    continue

                elif 'release' in value:
                    # retrieve active release distributions
                    src = config_data[key]['src']
                    revision = config_data[key]['revision']
                    project = config_data[key]['release']
                    keys, distributions = process_distributions(project, src, revision, debug)
                    metadata[key] = v = distributions
                    metadata[f"{key}-keys"] = keys
                    metadata[f"{key}-project"] = project
                    if debug:
                        print('RELEASE V:', v)

                elif 'url' in value:
                    # process a url based data source
                    load = url_data(value['url'], debug)
                    process_load(metadata, value, load, debug)

                elif 'file' in value:
                    # process a file from within the site tree
                    load = file_data(value['file'], debug)
                    process_load(metadata, value, load, debug)

                else:
                    # should probably be an error but doesn't matter
                    metadata[key] = value
            else:
                # simple metadata values - either an int or str
                if debug:
                    print(f'{key} = {value}')
                metadata[key] = value

    # display asfdata metadata or metadata type
    print('-----')
    for key in metadata:
        if debug:
            print(f'metadata[{key}] =')
            pp = pprint.PrettyPrinter(indent=2)
            pp.pprint(metadata[key])
            print('-----')
        elif isinstance(metadata[key], str):
            print(f'metadata[{key}] = "{metadata[key]}"')
        elif isinstance(metadata[key], int):
            print(f'metadata[{key}] = {metadata[key]}')
        elif isinstance(metadata[key], list):
            print(f'metadata[{key}] is a sequence.')
        elif isinstance(metadata[key], dict):
            print(f'metadata[{key}] is a dictionary.')
        else:
            keytype = type(metadata[key])
            print(f'metadata[{key}] is a {keytype}')
    print('-----')