Exemple #1
0
def parse_directory(**kwargs):
    """
    Get parsed json and yaml output for complete header directory
    """
    kwargs['output'] = True
    dir_path = kwargs['file_path']
    dir_path = os.path.abspath(dir_path)
    list_header = []
    dir_name = os.path.basename(dir_path)
    for _header in os.listdir(dir_path):
        if _header.endswith('.h') and os.path.isfile(os.path.join(dir_path, _header)):
            list_header.append(os.path.join(dir_path, _header))
    list_header = sorted(list_header)
    if list_header:
        for header_path in list_header:
            kwargs['file_path'] = header_path
            header = os.path.basename(header_path)
            try:
                parse_dir = BlockHeaderParser(**kwargs)
                parse_dir.yaml = True
                parse_dir.json = True
                run_blocktool(parse_dir)
                yaml_generator(parse_dir, **kwargs)
                if not kwargs['modtool']:
                    json_generator(parse_dir, **kwargs)
            except:
                logging.basicConfig(level=logging.DEBUG,
                                    filename=os.path.join('.', dir_name+'_log.out'))
                logging.exception(
                    'Log for Exception raised for the header: {}\n'.format(header))
                click.secho('Parsing unsuccessful: {}'.format(
                    header), fg='yellow')
    else:
        raise BlockToolException(
            'Invalid directory! No header found to be parsed')
Exemple #2
0
def cli(**kwargs):
    """
    Block header parsing tool.
    \b
    A tool that can be used to automatically parse the headers in GNU Radio project
    or the OOT modules
    """
    kwargs['modtool'] = False
    if os.path.isfile(kwargs['file_path']):
        parser = BlockHeaderParser(**kwargs)
        run_blocktool(parser)
        if kwargs['yaml']:
            parser.yaml = True
            yaml_generator(parser, **kwargs)
        else:
            parser.json_confirm = True
            json_generator(parser, **kwargs)
    elif os.path.isdir(kwargs['file_path']):
        parse_directory(**kwargs)
    else:
        raise BlockToolException('Invalid file or directory path.')