summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <juergen@ryannel.org>2018-11-22 13:19:20 +0100
committerJuergen Bocklage-Ryannel <juergen@ryannel.org>2018-11-22 13:19:20 +0100
commit85f89f975538344e4f596f3175f8dda0f2b4de98 (patch)
tree8ecc39dbb2f3534b6645392a3764c8dd65d4aac4
parentffa5e14659ea6c7c7ffd25725089678c239a9155 (diff)
parentc93019f848728b8fce3e706bedd9bbe72fd67364 (diff)
downloadqtivi-qface-85f89f975538344e4f596f3175f8dda0f2b4de98.tar.gz
Merge branch 'develop' of github.com:Pelagicore/qface into develop
# Conflicts: # qface/watch.py
-rw-r--r--.travis.yml4
-rw-r--r--docs/domain.rst4
-rw-r--r--docs/extending.rst6
-rw-r--r--docs/usage.rst2
-rw-r--r--qface/cli.py40
-rw-r--r--qface/generator.py23
-rw-r--r--qface/shell.py8
-rw-r--r--qface/templates/qface/qtcpp.j26
-rw-r--r--qface/utils.py17
-rw-r--r--qface/watch.py4
10 files changed, 86 insertions, 28 deletions
diff --git a/.travis.yml b/.travis.yml
index 8f76043..15c96ea 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
language: python
python:
- - "3.5"
+ - "3.6"
install: "pip install -r requirements.txt"
-script: ./cli.py test_ci
+script: ./cli.py test-ci
diff --git a/docs/domain.rst b/docs/domain.rst
index bf8f1c1..df27987 100644
--- a/docs/domain.rst
+++ b/docs/domain.rst
@@ -12,10 +12,10 @@ The IDL is converted into an in memory domain model (see qface/idl/domain.py)
- System
- Module
- Import
- - Service
+ - Interface
- Property
- Operation
- - Event
+ - Signal
- Enum
- Flag
- Struct
diff --git a/docs/extending.rst b/docs/extending.rst
index 910c086..faf4ccb 100644
--- a/docs/extending.rst
+++ b/docs/extending.rst
@@ -81,10 +81,12 @@ The rules document is divided into several targets. Each target can have an own
<target>:
<symbol>:
- context: {}
- destination: ''
+ context: { <key>: <value> }
+ destination: <path>
documents:
<target>:<source>
+ preserve:
+ <target>:<source>
* ``<target>`` is a name of the current target (e.g. client, server, plugin)
* ``<symbol>`` must be either system, module, interface, struct or enum
diff --git a/docs/usage.rst b/docs/usage.rst
index 74a1714..87216c7 100644
--- a/docs/usage.rst
+++ b/docs/usage.rst
@@ -57,7 +57,7 @@ This script reads the input directory and returns a system object from the domai
{% for module in system.modules %}
{%- for interface in module.interfaces -%}
- SERVICE, {{module}}.{{interface}}
+ INTERFACE, {{module}}.{{interface}}
{% endfor -%}
{%- for struct in module.structs -%}
STRUCT , {{module}}.{{struct}}
diff --git a/qface/cli.py b/qface/cli.py
new file mode 100644
index 0000000..f0b06b0
--- /dev/null
+++ b/qface/cli.py
@@ -0,0 +1,40 @@
+import sys
+import click
+from path import Path
+from qface.generator import FileSystem, RuleGenerator
+from qface.watch import monitor
+
+
+def run(config, src, dst, force=False, features=None):
+ project = Path(dst).name
+ system = FileSystem.parse(src)
+ template_dir = config.dirname() / 'templates'
+
+ context = {
+ 'dst': dst,
+ 'system': system,
+ 'project': project,
+ 'features': features,
+ }
+
+ generator = RuleGenerator(template_dir, destination=dst, context=context, features=features, force=force)
+ generator.process_rules(config, system)
+
+
+@click.command()
+@click.option('--config', '-c', type=click.Path(exists=True))
+@click.option('--reload/--no-reload', default=False)
+@click.option('--features', '-f', multiple=True)
+@click.option('--force/--no-force', default=True, help="Force writing of target files, ignores preserve")
+@click.argument('src', nargs=-1, type=click.Path(exists=True))
+@click.argument('dst', nargs=1, type=click.Path(exists=False, file_okay=False))
+def app(config, src, dst, features, reload, force):
+ """Takes several files or directories as src and generates the code
+ in the given dst directory."""
+ config = Path(config)
+ if reload:
+ argv = sys.argv.copy()
+ argv.remove('--reload')
+ monitor(config.dirname(), src, dst, argv)
+ else:
+ run(config, src, dst, force)
diff --git a/qface/generator.py b/qface/generator.py
index 1e1da41..b19cfa2 100644
--- a/qface/generator.py
+++ b/qface/generator.py
@@ -5,14 +5,15 @@ from jinja2 import Environment, Template, Undefined, StrictUndefined
from jinja2 import FileSystemLoader, PackageLoader, ChoiceLoader
from jinja2 import TemplateSyntaxError, TemplateNotFound, TemplateError
from path import Path
-from antlr4 import FileStream, CommonTokenStream, ParseTreeWalker
+from antlr4 import InputStream, FileStream, CommonTokenStream, ParseTreeWalker
from antlr4.error import DiagnosticErrorListener, ErrorListener
import shelve
import logging
import hashlib
import yaml
import click
-import sys, os
+import sys
+import os
from .idl.parser.TLexer import TLexer
from .idl.parser.TParser import TParser
@@ -20,7 +21,6 @@ from .idl.parser.TListener import TListener
from .idl.profile import EProfile
from .idl.domain import System
from .idl.listener import DomainListener
-from .utils import merge
from .filters import filters
from jinja2.debug import make_traceback as _make_traceback
@@ -33,6 +33,16 @@ except ImportError:
logger = logging.getLogger(__name__)
+def merge(a, b):
+ "merges b into a recursively if a and b are dicts"
+ for key in b:
+ if isinstance(a.get(key), dict) and isinstance(b.get(key), dict):
+ merge(a[key], b[key])
+ else:
+ a[key] = b[key]
+ return a
+
+
def template_error_handler(traceback):
exc_type, exc_obj, exc_tb = traceback.exc_info
error = exc_obj
@@ -280,6 +290,11 @@ class FileSystem(object):
sys.exit(-1)
@staticmethod
+ def parse_text(text: str, system: System = None, profile=EProfile.FULL):
+ stream = InputStream(text)
+ return FileSystem._parse_stream(stream, system, "<TEXT>", profile)
+
+ @staticmethod
def _parse_document(document: Path, system: System = None, profile=EProfile.FULL):
"""Parses a document and returns the resulting domain system
@@ -293,7 +308,7 @@ class FileSystem(object):
return system
@staticmethod
- def _parse_stream(stream, system: System = None, document=None, profile=EProfile.FULL):
+ def _parse_stream(stream: InputStream, system: System = None, document=None, profile=EProfile.FULL):
logger.debug('parse stream')
system = system or System()
diff --git a/qface/shell.py b/qface/shell.py
index 3d34d89..bf76f7c 100644
--- a/qface/shell.py
+++ b/qface/shell.py
@@ -6,11 +6,11 @@ API for interacting with the system shell
"""
-def sh(cmd, **kwargs):
+def sh(args, **kwargs):
"""
runs the given cmd as shell command
"""
- if not cmd:
+ if not args:
return
- click.echo('$ {0}'.format(cmd))
- return call(cmd, shell=True, **kwargs)
+ click.echo('$ {0}'.format(' '.join(args)))
+ return call(args, **kwargs)
diff --git a/qface/templates/qface/qtcpp.j2 b/qface/templates/qface/qtcpp.j2
index e522233..67b68f8 100644
--- a/qface/templates/qface/qtcpp.j2
+++ b/qface/templates/qface/qtcpp.j2
@@ -37,8 +37,8 @@ void {{symbol}}{{postfix}}();
/*!
\qmlproperty {{property.type}} {{class}}::{{property}}
{% with doc = property.comment|parse_doc %}
- \brief {{doc.brief}}
- {{doc.description}}
+ \brief {{doc.brief|join(" ")}}
+ {{doc.description|join("\n ")}}
{% endwith %}
*/
void {{class}}::set{{property|upperfirst}}({{ property|parameterType }})
@@ -68,7 +68,7 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameterType }})
\qmlmethod {{operation.type}} {{class}}::{{operation}}({{operation|parameters}})
{% with doc = operation.comment|parse_doc %}
\brief {{doc.brief}}
- {{doc.description}}
+ {{doc.description|join("\n ")}}
{% endwith %}
*/
{{operation|returnType}} {{class}}::{{operation}}({{operation|parameters}})
diff --git a/qface/utils.py b/qface/utils.py
index 3122d38..f816b58 100644
--- a/qface/utils.py
+++ b/qface/utils.py
@@ -1,10 +1,11 @@
+from .generator import FileSystem
+from .helper import doc
-def merge(a, b):
- "merges b into a recursively if a and b are dicts"
- for key in b:
- if isinstance(a.get(key), dict) and isinstance(b.get(key), dict):
- merge(a[key], b[key])
- else:
- a[key] = b[key]
- return a
+def module_info(text):
+ system = FileSystem.parse_text(text)
+ module = list(system.modules)[0]
+ return {
+ 'title': module.name,
+ 'brief': " ".join(doc.parse_doc(module.comment).brief)
+ }
diff --git a/qface/watch.py b/qface/watch.py
index 29bc30f..33fae01 100644
--- a/qface/watch.py
+++ b/qface/watch.py
@@ -3,7 +3,7 @@ from watchdog.observers import Observer
import click
from path import Path
import time
-from subprocess import call
+from .shell import sh
"""
Provides an API to monitor the file system
@@ -25,7 +25,7 @@ class RunScriptChangeHandler(FileSystemEventHandler):
if self.is_running:
return
self.is_running = True
- call(self.args, cwd=Path.getcwd())
+ sh(self.args, cwd=Path.getcwd())
self.is_running = False