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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/usr/bin/env python3
# Copyright (c) Pelagicore AB 2016
import click
import logging
import logging.config
import yaml
from path import Path
from qface.generator import FileSystem, Generator
from qface.helper.qtqml import Filters
from qface.watch import monitor
here = Path(__file__).dirname()
logging.config.dictConfig(yaml.load(open(here / 'log.yaml')))
log = logging.getLogger(__file__)
def run(src, dst):
log.debug('run {0} {1}'.format(src, dst))
system = FileSystem.parse(src)
generator = Generator(search_path=here / 'templates')
generator.register_filter('defaultValue', Filters.defaultValue)
generator.register_filter('propertyType', Filters.propertyType)
ctx = {'dst': dst}
for module in system.modules:
module_name = module.module_name
module_path = '/'.join(module.name_parts)
plugin_name = "".join(module.name_parts[:2])
ctx.update({
'module': module,
'module_name': module_name,
'module_path': module_path,
'plugin_name': plugin_name,
})
generator.destination = generator.apply("{{dst}}/{{module_path}}", ctx)
generator.write('private/{{module_name}}Module.js', 'module.js', ctx)
generator.write('qmldir', 'public_qmldir', ctx)
generator.write('private/qmldir', 'private_qmldir', ctx)
for interface in module.interfaces:
ctx.update({
'interface': interface,
})
generator.write('private/Abstract{{interface}}.qml', 'AbstractInterface.qml', ctx)
generator.write('{{interface}}.qml', 'Interface.qml', ctx, preserve=True)
@click.command()
@click.option('--reload/--no-reload', default=False)
@click.argument('src', nargs=-1, type=click.Path(exists=True))
@click.argument('dst', nargs=1, type=click.Path(exists=True))
def app(src, dst, reload):
"""Takes several files or directories as src and generates the code
in the given dst directory."""
if reload:
script = Path(__file__).abspath()
monitor(script, src, dst)
else:
run(src, dst)
if __name__ == '__main__':
app()
|