<commit_before>#!/usr/bin/env python

import sys
import os
import re
import argparse
import yaml
from mako.template import Template

valid_c_name_pattern = re.compile('[\W_]+')


def parse_event(e):
    e['name'] = valid_c_name_pattern.sub('_', e['name']).lower()
    if e.get('filter') is None:
        e.setdefault('filter', {}).setdefault('type', 'none')
    if e.get('action') is None:
        e.setdefault('action', {}).setdefault('type', 'noop')
    return e

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Phosphor Inventory Manager (PIM) YAML '
        'scanner and code generator.')
    parser.add_argument(
        '-o', '--output', dest='output',
        default='generated.cpp', help='Output file name.')
    parser.add_argument(
        '-d', '--dir', dest='inputdir',
        default=os.path.join('example', 'events'),
        help='Location of files to process.')
    parser.add_argument(
        '-i', '--interfaces', dest='interfaces',
        default=os.path.join('example', 'interfaces.yaml'),
        help='Location of interface file.'),
    parser.add_argument(
        '-t', '--template', dest='template',
        default='generated.mako.cpp',
        help='Location of mako template.')

    args = parser.parse_args()

    yaml_files = filter(
        lambda x: x.endswith('.yaml'),
        os.listdir(args.inputdir))

    events = []
    for x in yaml_files:
        with open(os.path.join(args.inputdir, x), 'r') as fd:
            for e in yaml.load(fd.read()).get('events', {}):
                events.append(parse_event(e))

    t = Template(filename=args.template)
    with open(args.interfaces, 'r') as fd:
        interfaces = yaml.load(fd.read())

    with open(args.output, 'w') as fd:
        fd.write(
            t.render(
                interfaces=interfaces,
                events=events))


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4<commit_msg>Look for interfaces.yaml in --dir<commit_after>#!/usr/bin/env python

import sys
import os
import re
import argparse
import yaml
from mako.template import Template

valid_c_name_pattern = re.compile('[\W_]+')


def parse_event(e):
    e['name'] = valid_c_name_pattern.sub('_', e['name']).lower()
    if e.get('filter') is None:
        e.setdefault('filter', {}).setdefault('type', 'none')
    if e.get('action') is None:
        e.setdefault('action', {}).setdefault('type', 'noop')
    return e

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Phosphor Inventory Manager (PIM) YAML '
        'scanner and code generator.')
    parser.add_argument(
        '-o', '--output', dest='output',
        default='generated.cpp', help='Output file name.')
    parser.add_argument(
        '-d', '--dir', dest='inputdir',
        default='example',
        help='Location of files to process.')
    parser.add_argument(
        '-t', '--template', dest='template',
        default='generated.mako.cpp',
        help='Location of mako template.')

    args = parser.parse_args()

    events_dir = os.path.join(args.inputdir, 'events')
    yaml_files = filter(
        lambda x: x.endswith('.yaml'),
        os.listdir(events_dir))

    events = []
    for x in yaml_files:
        with open(os.path.join(events_dir, x), 'r') as fd:
            for e in yaml.load(fd.read()).get('events', {}):
                events.append(parse_event(e))

    t = Template(filename=args.template)
    with open(os.path.join(args.inputdir, 'interfaces.yaml'), 'r') as fd:
        interfaces = yaml.load(fd.read())

    with open(args.output, 'w') as fd:
        fd.write(
            t.render(
                interfaces=interfaces,
                events=events))


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
{'fraction_non_alphanumeric': 0.15919342000530645, 'fraction_numerical': 0.0015919342000530645, 'mean_word_length': 2.717948717948718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1935143', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1179, 'n_words': 272}