aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbuiltin/qtcpp/qtcpp.py2
-rw-r--r--builtin/qtqml/qtqml.py2
-rwxr-xr-xcli.py8
-rw-r--r--docs/conf.py1
-rwxr-xr-xexamples/csv/csv.py2
-rw-r--r--qface/generator.py34
-rw-r--r--qface/idl/domain.py2
-rw-r--r--tests/test_generator.py6
8 files changed, 29 insertions, 28 deletions
diff --git a/builtin/qtcpp/qtcpp.py b/builtin/qtcpp/qtcpp.py
index 56882a7..a0ee0ce 100755
--- a/builtin/qtcpp/qtcpp.py
+++ b/builtin/qtcpp/qtcpp.py
@@ -21,7 +21,7 @@ log = logging.getLogger(__file__)
def run(src, dst):
log.debug('run {0} {1}'.format(src, dst))
system = FileSystem.parse(src)
- generator = Generator(searchpath=here / 'templates')
+ generator = Generator(search_path=here / 'templates')
generator.register_filter('returnType', Filters.returnType)
generator.register_filter('parameterType', Filters.parameterType)
generator.register_filter('defaultValue', Filters.defaultValue)
diff --git a/builtin/qtqml/qtqml.py b/builtin/qtqml/qtqml.py
index be714e0..224b4c2 100644
--- a/builtin/qtqml/qtqml.py
+++ b/builtin/qtqml/qtqml.py
@@ -21,7 +21,7 @@ log = logging.getLogger(__file__)
def run(src, dst):
log.debug('run {0} {1}'.format(src, dst))
system = FileSystem.parse(src)
- generator = Generator(searchpath=here / 'templates')
+ generator = Generator(search_path=here / 'templates')
generator.register_filter('defaultValue', Filters.defaultValue)
generator.register_filter('propertyType', Filters.propertyType)
ctx = {'dst': dst}
diff --git a/cli.py b/cli.py
index 4bbeaa1..833df20 100755
--- a/cli.py
+++ b/cli.py
@@ -150,14 +150,14 @@ def _generate_reload(generator, input, output):
event_handler.run() # run always once
observer = Observer()
path = generator.dirname().expand().abspath()
- print('watch:', path)
+ click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
for entry in input:
entry = entry.dirname().expand().abspath()
- print('watch:', entry)
+ click.secho('watch: {0}'.format(entry), fg='blue')
observer.schedule(event_handler, entry, recursive=True)
path = Path(__file__).parent / 'qface'
- print('watch:', path)
+ click.secho('watch: {0}'.format(path), fg='blue')
observer.schedule(event_handler, path, recursive=True)
observer.start()
@@ -174,7 +174,7 @@ def _generate_reload(generator, input, output):
def install(editable):
"""install the script onto the system using pip3"""
script_dir = str(Path(__file__).parent.abspath())
- print(script_dir)
+ click.secho(script_dir, fg='blue')
if editable:
sh('pip3 install --editable {0} --upgrade'.format(script_dir))
else:
diff --git a/docs/conf.py b/docs/conf.py
index d9d884c..e7aa601 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -23,7 +23,6 @@ import sys
here = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(here, '..'))
-print('path: ', sys.path)
# -- General configuration ------------------------------------------------
diff --git a/examples/csv/csv.py b/examples/csv/csv.py
index d885f91..bb27522 100755
--- a/examples/csv/csv.py
+++ b/examples/csv/csv.py
@@ -7,7 +7,7 @@ from qface.generator import FileSystem, Generator
def run(src, dst):
system = FileSystem.parse(src)
- generator = Generator(searchpath='templates')
+ generator = Generator(search_path='templates')
ctx = {'dst': dst, 'system': system}
generator.write('{{dst}}/modules.csv', 'modules.csv', ctx)
diff --git a/qface/generator.py b/qface/generator.py
index 6ef2aa4..0da3613 100644
--- a/qface/generator.py
+++ b/qface/generator.py
@@ -14,6 +14,8 @@ from .idl.parser.TListener import TListener
from .idl.domain import System
from .idl.listener import DomainListener
+import click
+
logger = logging.getLogger(__name__)
@@ -29,17 +31,16 @@ def upper_first_filter(s):
class Generator(object):
"""Manages the templates and applies your context data"""
- def __init__(self, searchpath: str):
- if searchpath:
- searchpath = Path(searchpath).expand()
+ def __init__(self, search_path: str):
+ if search_path:
+ search_path = Path(search_path).expand()
self.env = Environment(
- loader=FileSystemLoader(searchpath),
+ loader=FileSystemLoader(search_path),
trim_blocks=True,
lstrip_blocks=True
)
self.env.filters['upperfirst'] = upper_first_filter
self._destination = Path()
- self.prefix = ''
@property
def destination(self):
@@ -51,7 +52,7 @@ class Generator(object):
self._destination = Path(dst)
def get_template(self, name: str):
- """Retrievs a single template file from the template loader"""
+ """Retrieves a single template file from the template loader"""
return self.env.get_template(name)
def render(self, name: str, context: dict):
@@ -60,25 +61,26 @@ class Generator(object):
template = self.get_template(name)
return template.render(context)
- def apply(self, template: Template, context: dict):
+ def apply(self, template: str, context: dict):
"""Return the rendered text of a template instance"""
return self.env.from_string(template).render(context)
- def write(self, fileTemplate: str, template: str, context: dict, preserve=False):
- """Using a templated file name it renders a template
- into a file given a context"""
- path = self.destination / Path(self.apply(fileTemplate, context))
+ def write(self, file_path: str, template: str, context: dict, preserve=False):
+ """Using a template file name it renders a template
+ into a file given a context
+ """
+ path = self.destination / Path(self.apply(file_path, context))
path.parent.makedirs_p()
logger.info('write {0}'.format(path))
data = self.render(template, context)
- if self._hasDifferentContent(data, path):
+ if self._has_different_content(data, path):
if path.exists() and preserve:
- print('preserve changed file: {0}'.format(path))
+ click.secho('preserve changed file: {0}'.format(path), fg='blue')
else:
- print('write changed file: {0}'.format(path))
+ click.secho('write changed file: {0}'.format(path), fg='blue')
path.open('w').write(data)
- def _hasDifferentContent(self, data, path):
+ def _has_different_content(self, data, path):
if not path.exists():
return True
dataHash = hashlib.new('md5', data.encode('utf-8')).digest()
@@ -91,7 +93,7 @@ class Generator(object):
class FileSystem(object):
- """QFace helper function to work with the file system"""
+ """QFace helper functions to work with the file system"""
@staticmethod
def parse_document(path: str, system: System = None):
diff --git a/qface/idl/domain.py b/qface/idl/domain.py
index 6a6ece9..a325b55 100644
--- a/qface/idl/domain.py
+++ b/qface/idl/domain.py
@@ -55,7 +55,7 @@ class System(object):
# <module>.<Symbol>
(module_name, type_name) = self.split_typename(name)
if not module_name and type_name:
- print('not able to lookup symbol: {0}'.format(name))
+ click.secho('not able to lookup symbol: {0}'.format(name), fg='red')
return None
module = self._moduleMap[module_name]
return module.lookup(type_name)
diff --git a/tests/test_generator.py b/tests/test_generator.py
index 823c7fa..21c483c 100644
--- a/tests/test_generator.py
+++ b/tests/test_generator.py
@@ -19,7 +19,7 @@ def loadSystem():
def test_gen_module():
system = loadSystem()
- gen = Generator(searchpath='tests/templates')
+ gen = Generator(search_path='tests/templates')
template = "{{module}}"
module = system.lookup('com.pelagicore.ivi.tuner')
text = gen.apply(template, {"module": module})
@@ -28,7 +28,7 @@ def test_gen_module():
def test_gen_interface():
system = loadSystem()
- gen = Generator(searchpath='tests/templates')
+ gen = Generator(search_path='tests/templates')
template = """
{%- for interface in module.interfaces -%}
{{interface}}
@@ -65,7 +65,7 @@ def test_destination_prefix():
out = Path('tests/out')
out.rmtree_p()
out.makedirs_p()
- generator = Generator(searchpath='tests/templates')
+ generator = Generator(search_path='tests/templates')
for module in system.modules:
dst_template = '{{out}}/{{module|lower}}.txt'
ctx = {'out': out.abspath(), 'module': module}