diff options
-rw-r--r-- | qface/app.py | 46 | ||||
-rw-r--r-- | qface/filters.py | 9 | ||||
-rw-r--r-- | qface/generator.py | 11 | ||||
-rw-r--r-- | qface/helper/qtcpp.py | 32 | ||||
-rw-r--r-- | qface/helper/qtqml.py | 12 | ||||
-rw-r--r-- | qface/templates/qface/qtcpp.j2 | 4 | ||||
-rw-r--r-- | qface/watch.py | 9 | ||||
-rw-r--r-- | setup.py | 7 |
8 files changed, 97 insertions, 33 deletions
diff --git a/qface/app.py b/qface/app.py new file mode 100644 index 0000000..800744a --- /dev/null +++ b/qface/app.py @@ -0,0 +1,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() diff --git a/qface/filters.py b/qface/filters.py index de424a4..eba3c55 100644 --- a/qface/filters.py +++ b/qface/filters.py @@ -1,6 +1,6 @@ import json import hashlib - +from .helper import qtqml def jsonify(symbol): """ returns json format for symbol """ @@ -35,6 +35,10 @@ def path(symbol): return str(symbol).replace('.', '/') +def identifier(s): + return str(s).lower().replace('.', '_') + + filters = { 'jsonify': jsonify, 'upper_first': upper_first, @@ -43,4 +47,7 @@ filters = { 'lowerfirst': lower_first, 'hash': hash, 'path': path, + 'identifier': identifier, } + +filters.update(qtqml.Filters.get_filters()) diff --git a/qface/generator.py b/qface/generator.py index e65ad15..1e1da41 100644 --- a/qface/generator.py +++ b/qface/generator.py @@ -238,9 +238,11 @@ class RuleGenerator(Generator): self.context.update(rule.get('context', {})) self.destination = rule.get('destination', None) self.source = rule.get('source', None) - for target, source in rule.get('documents', {}).items(): + for entry in rule.get('documents', []): + target, source = self._resolve_rule_document(entry) self.write(target, source) - for target, source in rule.get('preserve', {}).items(): + for entry in rule.get('preserve', []): + target, source = self._resolve_rule_document(entry) self.write(target, source, preserve=True) def _shall_proceed(self, obj): @@ -252,6 +254,11 @@ class RuleGenerator(Generator): result = self.features.intersection(set(conditions)) return bool(len(result)) + def _resolve_rule_document(self, entry): + if type(entry) is dict: + return next(iter(entry.items())) + return (entry, entry) + class FileSystem(object): """QFace helper functions to work with the file system""" diff --git a/qface/helper/qtcpp.py b/qface/helper/qtcpp.py index 2c64e74..1ffa865 100644 --- a/qface/helper/qtcpp.py +++ b/qface/helper/qtcpp.py @@ -234,20 +234,20 @@ class Filters(object): @staticmethod def get_filters(): return { - 'defaultValue': Filters.defaultValue, - 'returnType': Filters.returnType, - 'parameterType': Filters.parameterType, - 'open_ns': Filters.open_ns, - 'close_ns': Filters.close_ns, - 'using_ns': Filters.using_ns, - 'ns': Filters.ns, - 'fqn': Filters.fqn, - 'signalName': Filters.signalName, - 'parameters': Filters.parameters, - 'signature': Filters.signature, - 'identifier': Filters.identifier, - 'path': Filters.path, - 'className': Filters.className, - 'source_dependencies': Filters.source_dependencies, - 'header_dependencies': Filters.header_dependencies, + 'qt.defaultValue': Filters.defaultValue, + 'qt.returnType': Filters.returnType, + 'qt.parameterType': Filters.parameterType, + 'qt.cpp_open_ns': Filters.open_ns, + 'qt.close_ns': Filters.close_ns, + 'qt.using_ns': Filters.using_ns, + 'qt.ns': Filters.ns, + 'qt.fqn': Filters.fqn, + 'qt.signalName': Filters.signalName, + 'qt.parameters': Filters.parameters, + 'qt.signature': Filters.signature, + 'qt.identifier': Filters.identifier, + 'qt.path': Filters.path, + 'qt.className': Filters.className, + 'qt.source_dependencies': Filters.source_dependencies, + 'qt.header_dependencies': Filters.header_dependencies, } diff --git a/qface/helper/qtqml.py b/qface/helper/qtqml.py index e29311f..915607d 100644 --- a/qface/helper/qtqml.py +++ b/qface/helper/qtqml.py @@ -60,10 +60,10 @@ class Filters(object): return t @staticmethod - def path(s): - return str(s).replace('.', '/') - - @staticmethod - def identifier(s): - return str(s).lower().replace('.', '_') + def get_filters(): + return { + 'qml.className': Filters.className, + 'qml.defaultValue': Filters.defaultValue, + 'qml.propertyType': Filters.propertyType, + } diff --git a/qface/templates/qface/qtcpp.j2 b/qface/templates/qface/qtcpp.j2 index 31c91fe..e522233 100644 --- a/qface/templates/qface/qtcpp.j2 +++ b/qface/templates/qface/qtcpp.j2 @@ -26,7 +26,7 @@ void set{{property|upperfirst}}({{ property|parameterType }}){{ending}} {%- endmacro %} {% macro signal_decl(symbol, postfix="") -%} -void {{symbol}}{{postfix}}({{symbol|parameters}}); +void {{symbol}}{{postfix}}(); {%- endmacro %} {% macro property_member_decl(property) -%} @@ -46,7 +46,7 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameterType }}) {% if notifiable %} if (m_{{property}} != {{property}}) { m_{{property}} = {{property}}; - Q_EMIT {{property}}Changed({{property}}); + Q_EMIT {{property}}Changed(); } {% else %} m_{{property}} = {{property}}; diff --git a/qface/watch.py b/qface/watch.py index e5d86ba..29bc30f 100644 --- a/qface/watch.py +++ b/qface/watch.py @@ -11,10 +11,9 @@ Provides an API to monitor the file system class RunScriptChangeHandler(FileSystemEventHandler): - def __init__(self, args, cwd): + def __init__(self, args): super().__init__() self.args = args - self.cwd = cwd self.is_running = False def on_modified(self, event): @@ -26,17 +25,17 @@ class RunScriptChangeHandler(FileSystemEventHandler): if self.is_running: return self.is_running = True - call(self.args, cwd=self.cwd) + call(self.args, cwd=Path.getcwd()) self.is_running = False -def monitor(args, watch, cwd=Path.getcwd()): +def monitor(args, watch): """ reloads the script given by argv when src files changes """ watch = watch if isinstance(watch, (list, tuple)) else [watch] watch = [Path(entry).expand().abspath() for entry in watch] - event_handler = RunScriptChangeHandler(args, cwd) + event_handler = RunScriptChangeHandler(args) observer = Observer() for entry in watch: if entry.isfile(): @@ -64,5 +64,10 @@ setup( 'watchdog', 'ipdb', ], - } + }, + entry_points={ + 'console_scripts': [ + 'qface = qface.app:main' + ], + }, ) |