summaryrefslogtreecommitdiff
path: root/gerbonara/__main__.py
blob: 57b37375d0133e316b52e4568a5774ce172d6ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3

import click

from .layers import LayerStack


@click.command()
@click.option('-t' ,'--top', help='Render board top side.', is_flag=True)
@click.option('-b' ,'--bottom', help='Render board bottom side.', is_flag=True)
@click.argument('gerber_dir_or_zip', type=click.Path(exists=True))
@click.argument('output_svg', required=False, default='-', type=click.File('w'))
def render(gerber_dir_or_zip, output_svg, top, bottom):
    if (bool(top) + bool(bottom))  != 1:
        raise click.UsageError('Excactly one of --top or --bottom must be given.')

    stack = LayerStack.open(gerber_dir_or_zip, lazy=True)
    print(f'Loaded {stack}')

    svg = stack.to_pretty_svg(side=('top' if top else 'bottom'))
    output_svg.write(str(svg))

if __name__ == '__main__':
    render()