Esempio n. 1
0
def read_inspirations():
    """
    Reads the info list about the games originals/inspirations from inspirations.md using the Lark parser grammar
    in grammar_listing.lark
    :return:
    """
    # read inspirations

    # read and parse inspirations
    grammar_file = os.path.join(c.code_path, 'grammar_listing.lark')
    inspirations = osg_parse.read_and_parse(c.inspirations_file, grammar_file,
                                            osg_parse.ListingTransformer)

    # now inspirations is a list of dictionaries for every entry with some properties

    # check for duplicate names entries
    names = [inspiration['Name'] for inspiration in inspirations]
    duplicate_names = (name for name in names if names.count(name) > 1)
    duplicate_names = set(
        duplicate_names)  # to avoid duplicates in duplicate_names
    if duplicate_names:
        raise RuntimeError('Duplicate inspiration names: {}'.format(
            ', '.join(duplicate_names)))

    # check for essential, valid fields
    for inspiration in inspirations:
        # check that essential fields are existing
        for field in c.essential_inspiration_fields:
            if field not in inspiration:
                raise RuntimeError(
                    'Essential field "{}" missing in inspiration {}'.format(
                        field, inspiration['Name']))
        # check that all fields are valid fields
        for field in inspiration.keys():
            if field not in c.valid_inspiration_fields:
                raise RuntimeError(
                    'Invalid field "{}" in inspiration {}.'.format(
                        field, inspiration['Name']))
        # url fields
        for field in c.url_inspiration_fields:
            if field in inspiration:
                content = inspiration[field]
                if any(not (
                        x.startswith('http://') or x.startswith('https://'))
                       for x in content):
                    raise RuntimeError(
                        'Invalid URL in field "{}" in inspiration {}.'.format(
                            field, inspiration['Name']))

    # convert to dictionary
    inspirations = {x['Name']: x for x in inspirations}

    return inspirations
Esempio n. 2
0
def read_developers():
    """

    :return:
    """
    grammar_file = os.path.join(c.code_path, 'grammar_listing.lark')
    developers = osg_parse.read_and_parse(c.developer_file, grammar_file,
                                          osg_parse.ListingTransformer)

    # now developers is a list of dictionaries for every entry with some properties

    # check for duplicate names entries
    names = [dev['Name'] for dev in developers]
    duplicate_names = (name for name in names if names.count(name) > 1)
    duplicate_names = set(
        duplicate_names)  # to avoid duplicates in duplicate_names
    if duplicate_names:
        print('Warning: duplicate developer names: {}'.format(
            ', '.join(duplicate_names)))

    # check for essential, valid fields
    for dev in developers:
        # check that essential fields are existing
        for field in c.essential_developer_fields:
            if field not in dev:
                raise RuntimeError(
                    'Essential field "{}" missing in developer {}'.format(
                        field, dev['Name']))
        # check that all fields are valid fields
        for field in dev.keys():
            if field not in c.valid_developer_fields:
                raise RuntimeError(
                    'Invalid field "{}" in developer {}.'.format(
                        field, dev['Name']))
        # url fields
        for field in c.url_developer_fields:
            if field in dev:
                content = dev[field]
                if any(not (
                        x.startswith('http://') or x.startswith('https://'))
                       for x in content):
                    raise RuntimeError(
                        'Invalid URL in field "{}" in developer {}.'.format(
                            field, dev['Name']))

    # convert to dictionary
    developers = {x['Name']: x for x in developers}

    return developers