summaryrefslogtreecommitdiff
path: root/qface/app.py
blob: 800744a4e42d47bad2516df351983e5e74f3470e (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# Copyright (c) Pelagicore AB 2016

import sys
import click
import logging
from path import Path
from qface.generator import FileSystem, RuleGenerator
from qface.watch import monitor

here = Path(__file__).dirname()
logging.basicConfig()


def run(spec, src, dst):
    spec = Path(spec)
    project = Path(dst).name
    system = FileSystem.parse(src)

    context = {
        'dst': dst,
        'system': system,
        'project': project,
    }

    generator = RuleGenerator(search_path=spec.dirname() / 'templates', destination=dst, context=context)
    generator.process_rules(spec, system)


@click.command()
@click.option('--spec', type=click.Path(exists=True, file_okay=True))
@click.option('--dst', type=click.Path(exists=False, file_okay=False))
@click.option('--reload/--no-reload', default=False, help="Auto reload script on changes")
@click.argument('src', nargs=-1, type=click.Path(exists=True))
def main(spec, dst, reload, src):
    spec = Path(spec)
    if reload:
        argv = sys.argv.copy()
        argv.remove('--reload')
        monitor(args=argv, watch=src + (spec.dirname(),))
    else:
        run(spec, src, dst)


if __name__ == '__main__':
    main()