import click
import yaml

# Cuba keywords that are excludes from DataContainers
CUBA_DATA_CONTAINER_EXLCUDE = ['Id', 'Position']


@click.command()
@click.argument('input', type=click.File('rb'))
@click.argument('output', type=click.File('wb'))
def python(input, output):
    """ Create the CUBA Enum for the DataContainer.
    """
    keywords = yaml.safe_load(input)

    lines = [
        '# code auto-generated by the cuba-generate.py script.\n',
        'from enum import IntEnum, unique\n',
        '\n',
        '\n',
        '@unique\n',
        'class CUBA(IntEnum):\n'
        '\n']
    template = "    {} = {}\n"
    for keyword in keywords:
        if keyword['name'] in CUBA_DATA_CONTAINER_EXLCUDE:
            continue
        lines.append(template.format(keyword['key'], keyword['number']))
    output.writelines(lines)

def table(

if __name__ == '__main__':
    python()

import click
import yaml

# Cuba keywords that are excludes from DataContainers
CUBA_DATA_CONTAINER_EXLCUDE = ['Id', 'Position']


@click.group()
def cli():
    """ Auto-generate code from cuba yaml description. """


@cli.command()
@click.argument('input', type=click.File('rb'))
@click.argument('output', type=click.File('wb'))
def python(input, output):
    """ Create the CUBA Enum for the DataContainer.
    """
    keywords = yaml.safe_load(input)

    lines = [
        '# code auto-generated by the cuba-generate.py script.\n',
        'from enum import IntEnum, unique\n',
        '\n',
        '\n',
        '@unique\n',
        'class CUBA(IntEnum):\n',
        '\n']
    template = "    {} = {}\n"
    for keyword in keywords:
        if keyword['name'] in CUBA_DATA_CONTAINER_EXLCUDE:
            continue
        lines.append(template.format(keyword['key'], keyword['number']))
    output.writelines(lines)


@cli.command()
@click.argument('input', type=click.File('rb'))
@click.argument('output', type=click.File('wb'))
def table(input, output):
    """ Create the CUBA DataContainer Table descriptions.
    """
    keywords = yaml.safe_load(input)

    lines = [
        '# code auto-generated by the cuba-generate.py script.\n',
        'import tables\n',
        '\n',
        '\n']

    # create Data table description
    lines.extend([
        'class Data(tables.IsDescription):\n',
        '\n'])
    template = "    {} = tables.{}Col(pos={}, shape=({}))\n"
    data_types = {
        'string': 'String',
        'double': 'Float64',
        'integer': 'Int32'}
    position = 0
    for keyword in keywords:
        if keyword['name'] in CUBA_DATA_CONTAINER_EXLCUDE:
            continue
        if len(keyword['shape']) == 1:
            shape = str(keyword['shape'][0]) + ','
        else:
            shape = ','.join(map(str, keyword['shape']))
        lines.append(template.format(
            keyword['key'].lower(),
            data_types[keyword['type']],
            position,
            shape))
        position += 1

    lines.append('\n\n')

    # create Mask table description
    mask_size = position
    lines.extend([
        'class Mask(tables.IsDescription):\n',
        '    mask = tables.BoolCol(shape=({},))\n'.format(mask_size)])

    output.writelines(lines)


if __name__ == '__main__':
    cli()

add autogeneration of the DataContainer group table descriptions