diff options
author | Mike Krus <mike.krus@kdab.com> | 2017-08-15 14:29:56 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2017-08-21 09:07:33 +0000 |
commit | 6145285f9f9c15928100590b15c45430241fb640 (patch) | |
tree | 1cbe44651b8da676683ea46f4cf4cbee4560ec7f | |
parent | 1369bb63ccfa6f5d3487d0a40c0644f7698030cb (diff) |
Add ability to specify template folder
This removes the ability to provide multiple format but it was useless
anyhow (as everything ended up in the same folder)
Task-number: QTAUTO-470
Change-Id: Ic47e5b3e6b07bbdcf650c57287e112cd2c6f890b
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r-- | src/doc/qtivi/src/generator-usage.qdoc | 8 | ||||
-rwxr-xr-x | src/tools/ivigenerator/generate.py | 29 |
2 files changed, 19 insertions, 18 deletions
diff --git a/src/doc/qtivi/src/generator-usage.qdoc b/src/doc/qtivi/src/generator-usage.qdoc index fce6d2f..f8bccf7 100644 --- a/src/doc/qtivi/src/generator-usage.qdoc +++ b/src/doc/qtivi/src/generator-usage.qdoc @@ -52,7 +52,7 @@ The options and parameters are: \li specifies whether the generator should keep track of the changes in the IDL file and update output on the fly (--no-reload by default) \row - \li -f, --format [frontend|backend_simulator] + \li -f, --format [frontend|backend_simulator|<folder>] \li see below \row \li --help @@ -76,9 +76,13 @@ These are: \li Generates a developer facing API using base classes from qtivicore and the \l {Dynamic Backend System} \row - \li backend simulator + \li backend_simulator \li Generates a simulation backend for the API generated by the "frontend" option. This backend serves as a mock implementation. + \row + \li folder path + \li Uses templates inside the folder. A YAML file with the same name as the folder (and .yaml + extension) should provide a list of template files in the folder (see YAML format specification below). \endtable \section1 YAML configuration diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index 7672dd9..2590438 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -58,6 +58,7 @@ log = logging.getLogger(__file__) Filters.classPrefix = '' QT_AS_VERSION = 2.0 +IVI_DEFAULT_TEMPLATES = ['frontend', 'backend_simulator', 'generation_validator', 'control_panel'] def tag_by_path(symbol, path, default_value=False): """ @@ -501,7 +502,7 @@ def model_type(symbol): def generate(tplconfig, moduleConfig, src, dst): log.debug('run {0} {1}'.format(src, dst)) system = FileSystem.parse(src) - generator = Generator(search_path=here / tplconfig) + generator = Generator(search_path=tplconfig) generator.register_filter('return_type', return_type) generator.register_filter('parameter_type', parameter_type) generator.register_filter('getter_name', getter_name) @@ -529,7 +530,7 @@ def generate(tplconfig, moduleConfig, src, dst): srcFile = os.path.basename(src[0]) srcBase = os.path.splitext(srcFile)[0] ctx = {'dst': dst, 'qtASVersion': QT_AS_VERSION, 'srcFile':srcFile, 'srcBase':srcBase} - gen_config = yaml.load(open(here / '{0}.yaml'.format(tplconfig))) + gen_config = yaml.load(open(here / '{0}.yaml'.format(os.path.basename(tplconfig)))) for module in system.modules: log.debug('generate code for module %s', module) module.add_tag('config') @@ -563,29 +564,25 @@ def generate(tplconfig, moduleConfig, src, dst): generator.write(rule['dest_file'], rule['template_file'], ctx, preserve) -def run(formats, moduleConfig, src, dst): - for f in formats: - switcher = { - 'frontend': 'templates_frontend', - 'backend_simulator': 'templates_backend_simulator', - 'generation_validator': 'templates_generation_validator', - 'control_panel': 'templates_control_panel' - } - tplConfig = switcher.get(f, 'unknown') - if tplConfig == 'unknown': - log.debug('unknown format {0}'.format(f)) +def run(format, moduleConfig, src, dst): + if format in IVI_DEFAULT_TEMPLATES: + tplConfig = 'templates_{0}'.format(format) + generate(here / tplConfig, moduleConfig, src, dst) + else: + if os.path.exists(format): + generate(format, moduleConfig, src, dst) else: - generate(tplConfig, moduleConfig, src, dst) + print('Format "{0}" is invalid. Should be one of {1} or an existing template folder'.format(format, IVI_DEFAULT_TEMPLATES)) @click.command() @click.option('--reload/--no-reload', default=False) -@click.option('--format', '-f', multiple=True, - type=click.Choice(['frontend', 'backend_simulator', 'generation_validator', 'ui', 'control_panel'])) +@click.option('--format', '-f', multiple=False) @click.option('--module', default=False) @click.option('--validation_info', 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, format, reload, module, validation_info): """Takes several files or directories as src and generates the code in the given dst directory.""" |