summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen@ryannel.org>2018-11-22 13:10:34 +0100
committerJuergen Bocklage-Ryannel <juergen@ryannel.org>2018-11-22 13:10:34 +0100
commitffa5e14659ea6c7c7ffd25725089678c239a9155 (patch)
treeea4fe2f7dc94a12cd5159db8025bb1eb3b90df17
parent2d6a4f42259cb137988538d5f2392d4602da1c9d (diff)
downloadqtivi-qface-ffa5e14659ea6c7c7ffd25725089678c239a9155.tar.gz
- add new qface binary to launch external rule files
- add ns to qtcpp/qtqml filters - restructured rules format, docs are now a list - changed monitor signature
-rw-r--r--qface/app.py46
-rw-r--r--qface/filters.py9
-rw-r--r--qface/generator.py11
-rw-r--r--qface/helper/qtcpp.py32
-rw-r--r--qface/helper/qtqml.py12
-rw-r--r--qface/templates/qface/qtcpp.j24
-rw-r--r--qface/watch.py9
-rw-r--r--setup.py7
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():
diff --git a/setup.py b/setup.py
index 8792426..d7b65eb 100644
--- a/setup.py
+++ b/setup.py
@@ -64,5 +64,10 @@ setup(
'watchdog',
'ipdb',
],
- }
+ },
+ entry_points={
+ 'console_scripts': [
+ 'qface = qface.app:main'
+ ],
+ },
)