Esempio n. 1
0
def read_entry(file):
    """
    Reads a single entry
    :param file: the entry file (without path)
    :return: the entry
    """

    # setup parser and transformer
    grammar_file = os.path.join(c.code_path, 'grammar_entries.lark')
    grammar = utils.read_text(grammar_file)
    parse = osg_parse.create(grammar, osg_parse.EntryTransformer)

    # read entry file
    content = utils.read_text(os.path.join(c.entries_path, file))
    if not content.endswith('\n'):
        content += '\n'

    # parse and transform entry content
    try:
        entry = parse(content)
        entry = [
            ('File', file),
        ] + entry  # add file information to the beginning
        entry = check_and_process_entry(entry)
    except Exception as e:
        print('{} - {}'.format(file, e))
        raise RuntimeError(e)

    return entry
Esempio n. 2
0
def read_entries():
    """
    Parses all entries and assembles interesting infos about them.
    """

    # setup parser and transformer
    grammar_file = os.path.join(c.code_path, 'grammar_entries.lark')
    grammar = utils.read_text(grammar_file)
    parse = osg_parse.create(grammar, osg_parse.EntryTransformer)

    # a database of all important infos about the entries
    entries = []

    # iterate over all entries
    exception_happened = None
    for file, _, content in entry_iterator():

        if not content.endswith('\n'):
            content += '\n'

        # parse and transform entry content
        try:
            entry = parse(content)
            entry = [
                ('File', file),
            ] + entry  # add file information to the beginning
            entry = check_and_process_entry(entry)
        except Exception as e:
            print('{} - {}'.format(file, e))
            exception_happened = e  # just store last one
            continue

        # add to list
        entries.append(entry)
    if exception_happened:
        print('error(s) while reading entries')
        raise exception_happened

    return entries