From 71fecfc9383f5bcb32452ec05ce2996a29f77384 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Wed, 10 Apr 2019 16:36:43 +0200 Subject: [PATCH 01/15] small fixes and cleanup --- CoTeTo/Loaders/CSVFile.py | 2 +- CoTeTo/Loaders/JSONFile.py | 3 ++- CoTeTo/Loaders/PickleFile.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CoTeTo/Loaders/CSVFile.py b/CoTeTo/Loaders/CSVFile.py index 8f29449..5f678f9 100644 --- a/CoTeTo/Loaders/CSVFile.py +++ b/CoTeTo/Loaders/CSVFile.py @@ -20,7 +20,7 @@ def load(self, uriList): for u in uriList: if isfile(u): self.logger.info('CSVFile - loading %s', u) - with open(u, r) as f: + with open(u, 'r') as f: dialect = Sniffer().sniff(f.read(1024)) f.seek(0) data[u] = DictReader(f, dialect) diff --git a/CoTeTo/Loaders/JSONFile.py b/CoTeTo/Loaders/JSONFile.py index 73e95de..c49af68 100644 --- a/CoTeTo/Loaders/JSONFile.py +++ b/CoTeTo/Loaders/JSONFile.py @@ -20,7 +20,8 @@ def load(self, uriList): for u in uriList: if isfile(u): self.logger.info('JSONFile - loading %s', u) - data[u] = load(open(u, 'r')) + with open(u, 'r') as f: + data[u] = load(f) else: data[u] = None self.logger.error('JSONFile - file not readable %s', u) diff --git a/CoTeTo/Loaders/PickleFile.py b/CoTeTo/Loaders/PickleFile.py index 68d50a9..5aaa298 100644 --- a/CoTeTo/Loaders/PickleFile.py +++ b/CoTeTo/Loaders/PickleFile.py @@ -20,7 +20,8 @@ def load(self, uriList): for u in uriList: if isfile(u): self.logger.info('PickleFile - loading %s', u) - data[u] = load(open(u, 'r')) + with open(u, 'r') as f: + data[u] = load(f) else: data[u] = None self.logger.error('PickleFile - file not readable %s', u) From 13e2ac975c56a8a10b026e572acbb5197c5d2337 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Wed, 10 Apr 2019 17:10:41 +0200 Subject: [PATCH 02/15] add ExampleMako --- Generators/ExampleMako/Filters/Filter01.py | 21 +++++++++++++++ Generators/ExampleMako/Package.inf | 18 +++++++++++++ Generators/ExampleMako/Templates/Main.mako | 30 ++++++++++++++++++++++ Generators/ExampleMako/Templates/Sub.mako | 2 ++ 4 files changed, 71 insertions(+) create mode 100644 Generators/ExampleMako/Filters/Filter01.py create mode 100644 Generators/ExampleMako/Package.inf create mode 100644 Generators/ExampleMako/Templates/Main.mako create mode 100644 Generators/ExampleMako/Templates/Sub.mako diff --git a/Generators/ExampleMako/Filters/Filter01.py b/Generators/ExampleMako/Filters/Filter01.py new file mode 100644 index 0000000..d426454 --- /dev/null +++ b/Generators/ExampleMako/Filters/Filter01.py @@ -0,0 +1,21 @@ +# a filter function is called with the following arguments: +# d - the data dictionary read from the loader +# systemCfg - system configuration +# generatorCfg - generator configuration +# logger - a logger instance + + +def filter01(d, systemCfg, generatorCfg, logger): + + # spread a message + logger.debug('hi there! This is a filter running from module: ' + __file__) + + x = d['dummy'] + + # manipulate some data + x['foo'] += 1 + + # add more data + x['bar'] = 2.0 * x['foo'] + + # no return needed - data is manipulated inplace diff --git a/Generators/ExampleMako/Package.inf b/Generators/ExampleMako/Package.inf new file mode 100644 index 0000000..ee2d26d --- /dev/null +++ b/Generators/ExampleMako/Package.inf @@ -0,0 +1,18 @@ +[GENERATOR] +name = ExampleMako +version = 1.0 +description = Example using the mako engine +author = Joerg Raedler jraedler@udk-berlin.de + +[LOADER] +name = TestDummy +minVer = 0.1 +maxVer = 2.0 + +[FILTER] +module = Filter01 +function = filter01 + +[TEMPLATE] +topFile = Main.mako +type = mako diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/ExampleMako/Templates/Main.mako new file mode 100644 index 0000000..262344f --- /dev/null +++ b/Generators/ExampleMako/Templates/Main.mako @@ -0,0 +1,30 @@ +# +# systemCfg - dictionary with information on the system and the environment +# Keys: ${' '.join(systemCfg.keys())} +# CoTeToVersion: ${systemCfg['version']} +# CoTeToPath: ${systemCfg['path']} +# Platform: ${systemCfg['platform']} +# FullPlatform: ${systemCfg['fullplatform']} +# Hostname: ${systemCfg['hostname']} +# Username: ${systemCfg['username']} +# GeneratorPath: ${', '.join(systemCfg['generatorPath'])} +# Timestamp: ${systemCfg['timestamp']()} +# Infostamp: ${systemCfg['infostamp']()} +# +# generatorCfg - configparser object with information on the used generator +# (this is contents of the Package.inf file) +# Sections: ${' '.join(generatorCfg.keys())} +# Name: ${generatorCfg['GENERATOR'].get('name')} +# Version: ${generatorCfg['GENERATOR'].get('version')} +# +# logger - an object to send logging messages +# this will not output None, but log a message: ${logger.info('The answer is 42!')} +# +# d - the data object read from the loader and (optionally) manipulated by the filter +# (this is usually a dictionary of the form filename : data_items, +# but this depends on the loader and filter code) +# Keys (Filenames/URIs): ${' '.join(d.keys())} + +The value of foo is ${d['dummy']['foo']}. + +<%include file="Sub.mako"/> diff --git a/Generators/ExampleMako/Templates/Sub.mako b/Generators/ExampleMako/Templates/Sub.mako new file mode 100644 index 0000000..c082879 --- /dev/null +++ b/Generators/ExampleMako/Templates/Sub.mako @@ -0,0 +1,2 @@ +Hello, I'm a sub template! +bar = ${d['dummy']['bar']} From d3da8b64098f4bc2277c47fb50fe70ccb567439a Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Wed, 10 Apr 2019 17:19:53 +0200 Subject: [PATCH 03/15] small changes --- Generators/ExampleMako/Package.inf | 3 +++ Generators/ExampleMako/Templates/Main.mako | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Generators/ExampleMako/Package.inf b/Generators/ExampleMako/Package.inf index ee2d26d..5caef6f 100644 --- a/Generators/ExampleMako/Package.inf +++ b/Generators/ExampleMako/Package.inf @@ -16,3 +16,6 @@ function = filter01 [TEMPLATE] topFile = Main.mako type = mako + +[MYCUSTOMSETTINGS] +answer = 42 diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/ExampleMako/Templates/Main.mako index 262344f..7722c9a 100644 --- a/Generators/ExampleMako/Templates/Main.mako +++ b/Generators/ExampleMako/Templates/Main.mako @@ -1,4 +1,6 @@ # +# The following objects can be used in templates: +# # systemCfg - dictionary with information on the system and the environment # Keys: ${' '.join(systemCfg.keys())} # CoTeToVersion: ${systemCfg['version']} @@ -16,9 +18,12 @@ # Sections: ${' '.join(generatorCfg.keys())} # Name: ${generatorCfg['GENERATOR'].get('name')} # Version: ${generatorCfg['GENERATOR'].get('version')} +# access to custom sections and values is also possible: +# Answer: ${generatorCfg['MYCUSTOMSETTINGS'].getint('answer')} # # logger - an object to send logging messages -# this will not output None, but log a message: ${logger.info('The answer is 42!')} +# this will output None, but log a message: ${logger.info('The answer is 42!')} +# suppress the output with this trick: ${logger.info('But what was the question?') or ''} # # d - the data object read from the loader and (optionally) manipulated by the filter # (this is usually a dictionary of the form filename : data_items, From d49fa78add308dc1f050c9702f9fe95097ea4b38 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Wed, 10 Apr 2019 17:36:09 +0200 Subject: [PATCH 04/15] ... --- Generators/ExampleMako/Templates/Main.mako | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/ExampleMako/Templates/Main.mako index 7722c9a..dea62e0 100644 --- a/Generators/ExampleMako/Templates/Main.mako +++ b/Generators/ExampleMako/Templates/Main.mako @@ -10,6 +10,8 @@ # Hostname: ${systemCfg['hostname']} # Username: ${systemCfg['username']} # GeneratorPath: ${', '.join(systemCfg['generatorPath'])} +# +# the following are functions and need to be executed: # Timestamp: ${systemCfg['timestamp']()} # Infostamp: ${systemCfg['infostamp']()} # @@ -18,12 +20,13 @@ # Sections: ${' '.join(generatorCfg.keys())} # Name: ${generatorCfg['GENERATOR'].get('name')} # Version: ${generatorCfg['GENERATOR'].get('version')} +# # access to custom sections and values is also possible: # Answer: ${generatorCfg['MYCUSTOMSETTINGS'].getint('answer')} # # logger - an object to send logging messages # this will output None, but log a message: ${logger.info('The answer is 42!')} -# suppress the output with this trick: ${logger.info('But what was the question?') or ''} +# suppress the output with this trick: ${logger.warning('But what was the question?') or ''} # # d - the data object read from the loader and (optionally) manipulated by the filter # (this is usually a dictionary of the form filename : data_items, @@ -32,4 +35,6 @@ The value of foo is ${d['dummy']['foo']}. +## Templates can be splitted and included: <%include file="Sub.mako"/> + From d044797d37644e12533e210a3e242ef39053f29d Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 13:57:02 +0200 Subject: [PATCH 05/15] ... --- Generators/ExampleMako/Filters/Filter01.py | 4 ++-- Generators/ExampleMako/Package.inf | 17 +++++++++++++++++ Generators/ExampleMako/Templates/Main.mako | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Generators/ExampleMako/Filters/Filter01.py b/Generators/ExampleMako/Filters/Filter01.py index d426454..410147d 100644 --- a/Generators/ExampleMako/Filters/Filter01.py +++ b/Generators/ExampleMako/Filters/Filter01.py @@ -5,10 +5,10 @@ # logger - a logger instance -def filter01(d, systemCfg, generatorCfg, logger): +def myfilter(d, systemCfg, generatorCfg, logger): # spread a message - logger.debug('hi there! This is a filter running from module: ' + __file__) + logger.debug('Hi there! This is a filter running from module: ' + __file__) x = d['dummy'] diff --git a/Generators/ExampleMako/Package.inf b/Generators/ExampleMako/Package.inf index 5caef6f..8064674 100644 --- a/Generators/ExampleMako/Package.inf +++ b/Generators/ExampleMako/Package.inf @@ -1,21 +1,38 @@ +# This is the main control file of a generator. +# It follows the syntax defined by pythons configparser module. +# More information: https://docs.python.org/3/library/configparser.html + +# The GENERATOR section defines the main attributes of this generator. +# The combination of name and version must be unique in your generator path. [GENERATOR] name = ExampleMako version = 1.0 description = Example using the mako engine author = Joerg Raedler jraedler@udk-berlin.de +# The LOADER section defines the used loader name and version. +# This loader must exist in the CoTeTo.Loaders package or must be included +# in the generator (see ExampleCustomLoader). [LOADER] name = TestDummy minVer = 0.1 maxVer = 2.0 +# The optional FILTER section defines a module and function to manipulate the +# data received from the loader before it is ued in the templates. [FILTER] module = Filter01 function = filter01 +# The TEMPLATE section defines the file name of the main template. +# mako is the default engine, but you can use jinja2 instead. +# To output more than one file you can use multiple sections with different names, +# see ExampleMultiOutput for details. [TEMPLATE] topFile = Main.mako type = mako +# All other sections and entries will be ignored by the CoTeTo system, but you can +# store information here which is available in custom loaders, filters and templates. [MYCUSTOMSETTINGS] answer = 42 diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/ExampleMako/Templates/Main.mako index dea62e0..5de04f6 100644 --- a/Generators/ExampleMako/Templates/Main.mako +++ b/Generators/ExampleMako/Templates/Main.mako @@ -16,7 +16,7 @@ # Infostamp: ${systemCfg['infostamp']()} # # generatorCfg - configparser object with information on the used generator -# (this is contents of the Package.inf file) +# (this is basically the contents of the Package.inf file) # Sections: ${' '.join(generatorCfg.keys())} # Name: ${generatorCfg['GENERATOR'].get('name')} # Version: ${generatorCfg['GENERATOR'].get('version')} @@ -33,7 +33,7 @@ # but this depends on the loader and filter code) # Keys (Filenames/URIs): ${' '.join(d.keys())} -The value of foo is ${d['dummy']['foo']}. +The value of foo is ${d['dummy']['foo']}. Please notice this value was manipulated by a filter function. ## Templates can be splitted and included: <%include file="Sub.mako"/> From 52cd8eb5b893fce459f89c43cc927863894a2bc0 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 13:57:46 +0200 Subject: [PATCH 06/15] ... --- Generators/ExampleMako/Filters/{Filter01.py => MyFilter.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Generators/ExampleMako/Filters/{Filter01.py => MyFilter.py} (100%) diff --git a/Generators/ExampleMako/Filters/Filter01.py b/Generators/ExampleMako/Filters/MyFilter.py similarity index 100% rename from Generators/ExampleMako/Filters/Filter01.py rename to Generators/ExampleMako/Filters/MyFilter.py From 0c23dcf47c5e3fbd1b18ae7db99b15853540b4bc Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 14:13:28 +0200 Subject: [PATCH 07/15] ... --- .../Filters/MyFilter.py} | 4 +- Generators/ExampleJinja2/Package.inf | 40 +++++++++++++++++++ .../ExampleJinja2/Templates/Main.jinja2 | 39 ++++++++++++++++++ .../Templates/Sub.jinja2 | 0 Generators/ExampleMako/Package.inf | 8 ++-- Generators/ExampleMako/Templates/Main.mako | 3 +- Generators/ExampleMako/Templates/Sub.mako | 2 +- Generators/TestJinja2/Package.inf | 18 --------- Generators/TestJinja2/Templates/Main.jinja2 | 13 ------ Generators/TestMako/Filters/Filter01.py | 21 ---------- Generators/TestMako/Package.inf | 18 --------- Generators/TestMako/Templates/Main.mako | 13 ------ Generators/TestMako/Templates/Sub.mako | 2 - 13 files changed, 88 insertions(+), 93 deletions(-) rename Generators/{TestJinja2/Filters/Filter01.py => ExampleJinja2/Filters/MyFilter.py} (79%) create mode 100644 Generators/ExampleJinja2/Package.inf create mode 100644 Generators/ExampleJinja2/Templates/Main.jinja2 rename Generators/{TestJinja2 => ExampleJinja2}/Templates/Sub.jinja2 (100%) delete mode 100644 Generators/TestJinja2/Package.inf delete mode 100644 Generators/TestJinja2/Templates/Main.jinja2 delete mode 100644 Generators/TestMako/Filters/Filter01.py delete mode 100644 Generators/TestMako/Package.inf delete mode 100644 Generators/TestMako/Templates/Main.mako delete mode 100644 Generators/TestMako/Templates/Sub.mako diff --git a/Generators/TestJinja2/Filters/Filter01.py b/Generators/ExampleJinja2/Filters/MyFilter.py similarity index 79% rename from Generators/TestJinja2/Filters/Filter01.py rename to Generators/ExampleJinja2/Filters/MyFilter.py index d426454..410147d 100644 --- a/Generators/TestJinja2/Filters/Filter01.py +++ b/Generators/ExampleJinja2/Filters/MyFilter.py @@ -5,10 +5,10 @@ # logger - a logger instance -def filter01(d, systemCfg, generatorCfg, logger): +def myfilter(d, systemCfg, generatorCfg, logger): # spread a message - logger.debug('hi there! This is a filter running from module: ' + __file__) + logger.debug('Hi there! This is a filter running from module: ' + __file__) x = d['dummy'] diff --git a/Generators/ExampleJinja2/Package.inf b/Generators/ExampleJinja2/Package.inf new file mode 100644 index 0000000..0e75eb3 --- /dev/null +++ b/Generators/ExampleJinja2/Package.inf @@ -0,0 +1,40 @@ +# This is the main control file of a generator. +# It follows the syntax defined by pythons configparser module. +# More information: https://docs.python.org/3/library/configparser.html + +# The GENERATOR section defines the main attributes of this generator. +# The combination of name and version must be unique in your generator path. +[GENERATOR] +name = ExampleJinja2 +version = 1.0 +description = Example using the alternative jinja2 engine +author = Joerg Raedler jraedler@udk-berlin.de + +# The LOADER section defines the used loader name and version. +# This loader must exist in the CoTeTo.Loaders package or must be included +# in the generator (see ExampleCustomLoader). +# This example just uses a dummy loader that generates some useless data items and does not need any input! +[LOADER] +name = TestDummy +minVer = 0.1 +maxVer = 2.0 + +# The optional FILTER section defines a module and function to manipulate the +# data received from the loader before it is ued in the templates. +[FILTER] +module = MyFilter +function = myfilter + +# The TEMPLATE section defines the file name of the main template. +# mako is the default engine, but you can use jinja2 instead. +# To output more than one file you can use multiple sections with different names, +# see ExampleMultiOutput for details. +[TEMPLATE] +topFile = Main.jinja2 +type = jinja2 + +# All other sections and entries will be ignored by the CoTeTo system, but you can +# store information here which is available in custom loaders, filters and templates. +# See ExampleCustomEntries for details. +[MYCUSTOMSETTINGS] +answer = 42 diff --git a/Generators/ExampleJinja2/Templates/Main.jinja2 b/Generators/ExampleJinja2/Templates/Main.jinja2 new file mode 100644 index 0000000..8d92ef4 --- /dev/null +++ b/Generators/ExampleJinja2/Templates/Main.jinja2 @@ -0,0 +1,39 @@ +# +# The following objects can be used in templates: +# +# systemCfg - dictionary with information on the system and the environment +# Keys: {{' '.join(systemCfg.keys())}} +# CoTeToVersion: {{systemCfg['version']}} +# CoTeToPath: {{systemCfg['path']}} +# Platform: {{systemCfg['platform']}} +# FullPlatform: {{systemCfg['fullplatform']}} +# Hostname: {{systemCfg['hostname']}} +# Username: {{systemCfg['username']}} +# GeneratorPath: {{', '.join(systemCfg['generatorPath'])}} +# +# the following are functions and need to be executed: +# Timestamp: {{systemCfg['timestamp']()}} +# Infostamp: {{systemCfg['infostamp']()}} +# +# generatorCfg - configparser object with information on the used generator +# (this is basically the contents of the Package.inf file) +# Sections: {{' '.join(generatorCfg.keys())}} +# Name: {{generatorCfg['GENERATOR'].get('name')}} +# Version: {{generatorCfg['GENERATOR'].get('version')}} +# +# access to custom sections and values is also possible: +# Answer: {{generatorCfg['MYCUSTOMSETTINGS'].getint('answer')}} +# +# logger - an object to send logging messages +# this will output None, but log a message: {{logger.info('The answer is 42!')}} +# suppress the output with this trick: {{logger.warning('But what was the question?') or ''}} +# +# d - the data object read from the loader and (optionally) manipulated by the filter +# (this is usually a dictionary of the form filename : data_items, +# but this depends on the loader and filter code) +# Keys (Filenames/URIs): {{' '.join(d.keys())}} + +The value of foo is {{d['dummy']['foo']}}. Please notice this value was manipulated by a filter function. + +## Templates can be splitted and included: +{% include 'Sub.jinja2' %} diff --git a/Generators/TestJinja2/Templates/Sub.jinja2 b/Generators/ExampleJinja2/Templates/Sub.jinja2 similarity index 100% rename from Generators/TestJinja2/Templates/Sub.jinja2 rename to Generators/ExampleJinja2/Templates/Sub.jinja2 diff --git a/Generators/ExampleMako/Package.inf b/Generators/ExampleMako/Package.inf index 8064674..2094437 100644 --- a/Generators/ExampleMako/Package.inf +++ b/Generators/ExampleMako/Package.inf @@ -7,12 +7,13 @@ [GENERATOR] name = ExampleMako version = 1.0 -description = Example using the mako engine +description = Example using the default mako engine author = Joerg Raedler jraedler@udk-berlin.de # The LOADER section defines the used loader name and version. # This loader must exist in the CoTeTo.Loaders package or must be included # in the generator (see ExampleCustomLoader). +# This example just uses a dummy loader that generates some useless data items and does not need any input! [LOADER] name = TestDummy minVer = 0.1 @@ -21,8 +22,8 @@ maxVer = 2.0 # The optional FILTER section defines a module and function to manipulate the # data received from the loader before it is ued in the templates. [FILTER] -module = Filter01 -function = filter01 +module = MyFilter +function = myfilter # The TEMPLATE section defines the file name of the main template. # mako is the default engine, but you can use jinja2 instead. @@ -34,5 +35,6 @@ type = mako # All other sections and entries will be ignored by the CoTeTo system, but you can # store information here which is available in custom loaders, filters and templates. +# See ExampleCustomEntries for details. [MYCUSTOMSETTINGS] answer = 42 diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/ExampleMako/Templates/Main.mako index 5de04f6..ed3763f 100644 --- a/Generators/ExampleMako/Templates/Main.mako +++ b/Generators/ExampleMako/Templates/Main.mako @@ -36,5 +36,4 @@ The value of foo is ${d['dummy']['foo']}. Please notice this value was manipulated by a filter function. ## Templates can be splitted and included: -<%include file="Sub.mako"/> - +<%include file="Sub.mako"/> \ No newline at end of file diff --git a/Generators/ExampleMako/Templates/Sub.mako b/Generators/ExampleMako/Templates/Sub.mako index c082879..965af39 100644 --- a/Generators/ExampleMako/Templates/Sub.mako +++ b/Generators/ExampleMako/Templates/Sub.mako @@ -1,2 +1,2 @@ Hello, I'm a sub template! -bar = ${d['dummy']['bar']} +bar = ${d['dummy']['bar']} \ No newline at end of file diff --git a/Generators/TestJinja2/Package.inf b/Generators/TestJinja2/Package.inf deleted file mode 100644 index eb5e7f4..0000000 --- a/Generators/TestJinja2/Package.inf +++ /dev/null @@ -1,18 +0,0 @@ -[GENERATOR] -name = TestJinja2 -version = 0.1 -description = test the jinja2 engine -author = Joerg Raedler jraedler@udk-berlin.de - -[LOADER] -name = TestDummy -minVer = 0.1 -maxVer = 2.0 - -[FILTER] -module = Filter01 -function = filter01 - -[TEMPLATE] -topFile = Main.jinja2 -type = jinja2 diff --git a/Generators/TestJinja2/Templates/Main.jinja2 b/Generators/TestJinja2/Templates/Main.jinja2 deleted file mode 100644 index a3812bd..0000000 --- a/Generators/TestJinja2/Templates/Main.jinja2 +++ /dev/null @@ -1,13 +0,0 @@ -# -# CoTeTo -# Info: {{systemCfg['infostamp']()}} -# Path: {{systemCfg['path']}} -# Gen-Path: {{', '.join(systemCfg['generatorPath'])}} -# -# Generator -# Name: {{generatorCfg['GENERATOR'].get('name')}} -# Version: {{generatorCfg['GENERATOR'].get('version')}} - -The value of foo is {{d['dummy']['foo']}}. - -{% include 'Sub.jinja2' %} diff --git a/Generators/TestMako/Filters/Filter01.py b/Generators/TestMako/Filters/Filter01.py deleted file mode 100644 index d426454..0000000 --- a/Generators/TestMako/Filters/Filter01.py +++ /dev/null @@ -1,21 +0,0 @@ -# a filter function is called with the following arguments: -# d - the data dictionary read from the loader -# systemCfg - system configuration -# generatorCfg - generator configuration -# logger - a logger instance - - -def filter01(d, systemCfg, generatorCfg, logger): - - # spread a message - logger.debug('hi there! This is a filter running from module: ' + __file__) - - x = d['dummy'] - - # manipulate some data - x['foo'] += 1 - - # add more data - x['bar'] = 2.0 * x['foo'] - - # no return needed - data is manipulated inplace diff --git a/Generators/TestMako/Package.inf b/Generators/TestMako/Package.inf deleted file mode 100644 index 340a989..0000000 --- a/Generators/TestMako/Package.inf +++ /dev/null @@ -1,18 +0,0 @@ -[GENERATOR] -name = TestMako -version = 0.1 -description = test the mako engine -author = Joerg Raedler jraedler@udk-berlin.de - -[LOADER] -name = TestDummy -minVer = 0.1 -maxVer = 2.0 - -[FILTER] -module = Filter01 -function = filter01 - -[TEMPLATE] -topFile = Main.mako -type = mako diff --git a/Generators/TestMako/Templates/Main.mako b/Generators/TestMako/Templates/Main.mako deleted file mode 100644 index f282ca2..0000000 --- a/Generators/TestMako/Templates/Main.mako +++ /dev/null @@ -1,13 +0,0 @@ -# -# CoTeTo -# Info: ${systemCfg['infostamp']()} -# Path: ${systemCfg['path']} -# Gen-Path: ${', '.join(systemCfg['generatorPath'])} -# -# Generator -# Name: ${generatorCfg['GENERATOR'].get('name')} -# Version: ${generatorCfg['GENERATOR'].get('version')} - -The value of foo is ${d['dummy']['foo']}. - -<%include file="Sub.mako"/> diff --git a/Generators/TestMako/Templates/Sub.mako b/Generators/TestMako/Templates/Sub.mako deleted file mode 100644 index c082879..0000000 --- a/Generators/TestMako/Templates/Sub.mako +++ /dev/null @@ -1,2 +0,0 @@ -Hello, I'm a sub template! -bar = ${d['dummy']['bar']} From dfdcbee1f0de09655ac937be25eb328f2c40948b Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 14:21:05 +0200 Subject: [PATCH 08/15] ... --- .../Filters/MyFilter.py | 0 .../{ExampleMako => Example01Mako}/Package.inf | 2 +- .../Templates/Main.mako | 0 .../Templates/Sub.mako | 0 .../Filters/MyFilter.py | 0 .../Package.inf | 2 +- .../Templates/Main.jinja2 | 0 .../Templates/Sub.jinja2 | 0 Generators/ExampleCustomEntries/Package.inf | 18 ++++++++++++++++++ .../Templates/Main.tmpl | 11 +---------- Generators/TestCustomEntries/Package.inf | 18 ------------------ 11 files changed, 21 insertions(+), 30 deletions(-) rename Generators/{ExampleJinja2 => Example01Mako}/Filters/MyFilter.py (100%) rename Generators/{ExampleMako => Example01Mako}/Package.inf (98%) rename Generators/{ExampleMako => Example01Mako}/Templates/Main.mako (100%) rename Generators/{ExampleMako => Example01Mako}/Templates/Sub.mako (100%) rename Generators/{ExampleMako => Example02Jinja2}/Filters/MyFilter.py (100%) rename Generators/{ExampleJinja2 => Example02Jinja2}/Package.inf (98%) rename Generators/{ExampleJinja2 => Example02Jinja2}/Templates/Main.jinja2 (100%) rename Generators/{ExampleJinja2 => Example02Jinja2}/Templates/Sub.jinja2 (100%) create mode 100644 Generators/ExampleCustomEntries/Package.inf rename Generators/{TestCustomEntries => ExampleCustomEntries}/Templates/Main.tmpl (52%) delete mode 100644 Generators/TestCustomEntries/Package.inf diff --git a/Generators/ExampleJinja2/Filters/MyFilter.py b/Generators/Example01Mako/Filters/MyFilter.py similarity index 100% rename from Generators/ExampleJinja2/Filters/MyFilter.py rename to Generators/Example01Mako/Filters/MyFilter.py diff --git a/Generators/ExampleMako/Package.inf b/Generators/Example01Mako/Package.inf similarity index 98% rename from Generators/ExampleMako/Package.inf rename to Generators/Example01Mako/Package.inf index 2094437..c872b41 100644 --- a/Generators/ExampleMako/Package.inf +++ b/Generators/Example01Mako/Package.inf @@ -5,7 +5,7 @@ # The GENERATOR section defines the main attributes of this generator. # The combination of name and version must be unique in your generator path. [GENERATOR] -name = ExampleMako +name = Example01Mako version = 1.0 description = Example using the default mako engine author = Joerg Raedler jraedler@udk-berlin.de diff --git a/Generators/ExampleMako/Templates/Main.mako b/Generators/Example01Mako/Templates/Main.mako similarity index 100% rename from Generators/ExampleMako/Templates/Main.mako rename to Generators/Example01Mako/Templates/Main.mako diff --git a/Generators/ExampleMako/Templates/Sub.mako b/Generators/Example01Mako/Templates/Sub.mako similarity index 100% rename from Generators/ExampleMako/Templates/Sub.mako rename to Generators/Example01Mako/Templates/Sub.mako diff --git a/Generators/ExampleMako/Filters/MyFilter.py b/Generators/Example02Jinja2/Filters/MyFilter.py similarity index 100% rename from Generators/ExampleMako/Filters/MyFilter.py rename to Generators/Example02Jinja2/Filters/MyFilter.py diff --git a/Generators/ExampleJinja2/Package.inf b/Generators/Example02Jinja2/Package.inf similarity index 98% rename from Generators/ExampleJinja2/Package.inf rename to Generators/Example02Jinja2/Package.inf index 0e75eb3..b7baf39 100644 --- a/Generators/ExampleJinja2/Package.inf +++ b/Generators/Example02Jinja2/Package.inf @@ -5,7 +5,7 @@ # The GENERATOR section defines the main attributes of this generator. # The combination of name and version must be unique in your generator path. [GENERATOR] -name = ExampleJinja2 +name = Example02Jinja2 version = 1.0 description = Example using the alternative jinja2 engine author = Joerg Raedler jraedler@udk-berlin.de diff --git a/Generators/ExampleJinja2/Templates/Main.jinja2 b/Generators/Example02Jinja2/Templates/Main.jinja2 similarity index 100% rename from Generators/ExampleJinja2/Templates/Main.jinja2 rename to Generators/Example02Jinja2/Templates/Main.jinja2 diff --git a/Generators/ExampleJinja2/Templates/Sub.jinja2 b/Generators/Example02Jinja2/Templates/Sub.jinja2 similarity index 100% rename from Generators/ExampleJinja2/Templates/Sub.jinja2 rename to Generators/Example02Jinja2/Templates/Sub.jinja2 diff --git a/Generators/ExampleCustomEntries/Package.inf b/Generators/ExampleCustomEntries/Package.inf new file mode 100644 index 0000000..752701c --- /dev/null +++ b/Generators/ExampleCustomEntries/Package.inf @@ -0,0 +1,18 @@ +[GENERATOR] +name = Example03CustomEntries +version = 1.0 +description = show the usage of custom entries in Package.inf +author = Joerg Raedler jraedler@udk-berlin.de + +# You can add custom sections and entries and use the values in the loader, filter and templates. +# Everything in this file is available as generatorCfg. +[FOO_BAR] +say_hello = 1 + +[LOADER] +name = TestDummy +minVer = 0.1 +maxVer = 2.0 + +[TEMPLATE] +topFile = Main.tmpl diff --git a/Generators/TestCustomEntries/Templates/Main.tmpl b/Generators/ExampleCustomEntries/Templates/Main.tmpl similarity index 52% rename from Generators/TestCustomEntries/Templates/Main.tmpl rename to Generators/ExampleCustomEntries/Templates/Main.tmpl index b7e43bf..657ddc2 100644 --- a/Generators/TestCustomEntries/Templates/Main.tmpl +++ b/Generators/ExampleCustomEntries/Templates/Main.tmpl @@ -1,13 +1,4 @@ -# -# CoTeTo -# Info: ${systemCfg['infostamp']()} -# Path: ${systemCfg['path']} -# Gen-Path: ${', '.join(systemCfg['generatorPath'])} -# -# Generator -# Name: ${generatorCfg['GENERATOR'].get('name')} -# Version: ${generatorCfg['GENERATOR'].get('version')} - +# ${systemCfg['infostamp']()} % if generatorCfg['FOO_BAR'].getboolean('say_hello'): Hello! Try to change the custom value in Package.inf, reload the generator and run again! diff --git a/Generators/TestCustomEntries/Package.inf b/Generators/TestCustomEntries/Package.inf deleted file mode 100644 index 9b0ca1c..0000000 --- a/Generators/TestCustomEntries/Package.inf +++ /dev/null @@ -1,18 +0,0 @@ -[GENERATOR] -name = TestCustomEntries -version = 0.1 -description = test custom entries in Package.ini -author = Joerg Raedler jraedler@udk-berlin.de - -# you can add custom sections and entries -# and use the values in the loader, filter and templates -[FOO_BAR] -say_hello = 1 - -[LOADER] -name = TestDummy -minVer = 0.1 -maxVer = 2.0 - -[TEMPLATE] -topFile = Main.tmpl From f66e64b3e0cbc908e34d337045fafcd91f8ddbbd Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 14:33:46 +0200 Subject: [PATCH 09/15] ... --- .../Package.inf | 0 .../Templates/Main.tmpl | 0 Generators/Example04MultiOutput/Package.inf | 24 +++++++++++++++++++ .../Templates/numberlines.tmpl | 0 .../Templates/statistics.tmpl | 0 .../Loaders/MyLoader.py | 0 Generators/Example05CustomLoaders/Package.inf | 18 ++++++++++++++ .../Templates/Main.tmpl | 0 Generators/TestCustomLoaders/Package.inf | 14 ----------- Generators/TestMultiOutput/Package.inf | 22 ----------------- foo | 22 +++++++++++++++++ 11 files changed, 64 insertions(+), 36 deletions(-) rename Generators/{ExampleCustomEntries => Example03CustomEntries}/Package.inf (100%) rename Generators/{ExampleCustomEntries => Example03CustomEntries}/Templates/Main.tmpl (100%) create mode 100644 Generators/Example04MultiOutput/Package.inf rename Generators/{TestMultiOutput => Example04MultiOutput}/Templates/numberlines.tmpl (100%) rename Generators/{TestMultiOutput => Example04MultiOutput}/Templates/statistics.tmpl (100%) rename Generators/{TestCustomLoaders => Example05CustomLoaders}/Loaders/MyLoader.py (100%) create mode 100644 Generators/Example05CustomLoaders/Package.inf rename Generators/{TestCustomLoaders => Example05CustomLoaders}/Templates/Main.tmpl (100%) delete mode 100644 Generators/TestCustomLoaders/Package.inf delete mode 100644 Generators/TestMultiOutput/Package.inf create mode 100644 foo diff --git a/Generators/ExampleCustomEntries/Package.inf b/Generators/Example03CustomEntries/Package.inf similarity index 100% rename from Generators/ExampleCustomEntries/Package.inf rename to Generators/Example03CustomEntries/Package.inf diff --git a/Generators/ExampleCustomEntries/Templates/Main.tmpl b/Generators/Example03CustomEntries/Templates/Main.tmpl similarity index 100% rename from Generators/ExampleCustomEntries/Templates/Main.tmpl rename to Generators/Example03CustomEntries/Templates/Main.tmpl diff --git a/Generators/Example04MultiOutput/Package.inf b/Generators/Example04MultiOutput/Package.inf new file mode 100644 index 0000000..6b67a13 --- /dev/null +++ b/Generators/Example04MultiOutput/Package.inf @@ -0,0 +1,24 @@ +[GENERATOR] +name = Example04MultiOutput +version = 1.0 +description = Output the lines of the input text files with line numbers added, generate a second file with some statistics +author = Joerg Raedler jraedler@udk-berlin.de + +[LOADER] +name = TextFile +minVer = 0.1 +maxVer = 2.0 + +# Any section name that starts with the string TEMPLATE can be used. +# All template sections are executed in alphabetical order. +# The extension ext will be appended to the output file or folder name. + +[TEMPLATE_NUMB] +topFile = numberlines.tmpl +type = mako +ext = .numbered + +[TEMPLATE_STAT] +topFile = statistics.tmpl +type = mako +ext = .statistics diff --git a/Generators/TestMultiOutput/Templates/numberlines.tmpl b/Generators/Example04MultiOutput/Templates/numberlines.tmpl similarity index 100% rename from Generators/TestMultiOutput/Templates/numberlines.tmpl rename to Generators/Example04MultiOutput/Templates/numberlines.tmpl diff --git a/Generators/TestMultiOutput/Templates/statistics.tmpl b/Generators/Example04MultiOutput/Templates/statistics.tmpl similarity index 100% rename from Generators/TestMultiOutput/Templates/statistics.tmpl rename to Generators/Example04MultiOutput/Templates/statistics.tmpl diff --git a/Generators/TestCustomLoaders/Loaders/MyLoader.py b/Generators/Example05CustomLoaders/Loaders/MyLoader.py similarity index 100% rename from Generators/TestCustomLoaders/Loaders/MyLoader.py rename to Generators/Example05CustomLoaders/Loaders/MyLoader.py diff --git a/Generators/Example05CustomLoaders/Package.inf b/Generators/Example05CustomLoaders/Package.inf new file mode 100644 index 0000000..2dec512 --- /dev/null +++ b/Generators/Example05CustomLoaders/Package.inf @@ -0,0 +1,18 @@ +[GENERATOR] +name = Example05CustomLoaders +version = 1.0 +description = test custom loaders - please load test/custom.txt as input +author = Joerg Raedler jraedler@udk-berlin.de + +# A set of standard loaders is available in the package CoTeTo.Loaders, +# but you can include your custom loader code in a generator. If the a value +# for module is set in the LOADER section, CoTeTo will look for the module in +# the Loaders folder of the generator. +[LOADER] +name = MyLoader +module = MyLoader +minVer = 0.1 +maxVer = 2.0 + +[TEMPLATE] +topFile = Main.tmpl diff --git a/Generators/TestCustomLoaders/Templates/Main.tmpl b/Generators/Example05CustomLoaders/Templates/Main.tmpl similarity index 100% rename from Generators/TestCustomLoaders/Templates/Main.tmpl rename to Generators/Example05CustomLoaders/Templates/Main.tmpl diff --git a/Generators/TestCustomLoaders/Package.inf b/Generators/TestCustomLoaders/Package.inf deleted file mode 100644 index e067c3e..0000000 --- a/Generators/TestCustomLoaders/Package.inf +++ /dev/null @@ -1,14 +0,0 @@ -[GENERATOR] -name = TestCustomLoaders -version = 0.1 -description = test custom loaders - please load test/custom.txt as input -author = Joerg Raedler jraedler@udk-berlin.de - -[LOADER] -name = MyLoader -module = MyLoader -minVer = 0.1 -maxVer = 2.0 - -[TEMPLATE] -topFile = Main.tmpl diff --git a/Generators/TestMultiOutput/Package.inf b/Generators/TestMultiOutput/Package.inf deleted file mode 100644 index 858364c..0000000 --- a/Generators/TestMultiOutput/Package.inf +++ /dev/null @@ -1,22 +0,0 @@ -[GENERATOR] -name = TestMultiOutput -version = 0.1 -description = Output the lines of the input files with line numbers added, generate a file with some statistics -author = Joerg Raedler - -[LOADER] -name = TextFile -minVer = 0.1 -maxVer = 2.0 - -# any section name that starts with the string TEMPLATE can be used - -[TEMPLATE_NUMB] -topFile = numberlines.tmpl -type = mako -ext = .numbered - -[TEMPLATE_STAT] -topFile = statistics.tmpl -type = mako -ext = .statistics diff --git a/foo b/foo new file mode 100644 index 0000000..28c668a --- /dev/null +++ b/foo @@ -0,0 +1,22 @@ +# +# CoTeTo +# Version: 0.99 +# Platform: win32 +# Path: C:\Users\jraedler\Devel\CoTeTo\CoTeTo +# Gen-Path: C:\Users\jraedler\Devel\CoTeTo\Generators, C:\Users\jraedler\Devel\CoTeTo_Generators +# +# Generator +# Name: Example05CustomLoaders +# Version: 1.0 + +File: C:/Users/jraedler/Devel/CoTeTo/test/custom.txt + Key: "foo" + Value: "bar" + + Key: "x" + Value: "y:z" + + Key: "spam" + Value: "eggs" + + From cddff5956cd09c8f8f720023ce2e06ce174145e8 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 14:54:41 +0200 Subject: [PATCH 10/15] ... --- Generators/Example06PostExec/Package.inf | 24 ++++++++++++ .../Example06PostExec/Templates/Main.mako | 36 ++++++++++++++++++ Generators/Example07NumberLines/Package.inf | 14 +++++++ .../Templates/numberlines.mao | 0 Generators/Example08Zip.zip | Bin 0 -> 3512 bytes Generators/NumberLines/Package.inf | 14 ------- Generators/README.md | 4 +- Generators/TestPostExec/Filters/Filter01.py | 21 ---------- Generators/TestPostExec/Package.inf | 22 ----------- Generators/TestPostExec/Templates/Main.mako | 13 ------- Generators/TestPostExec/Templates/Sub.mako | 2 - Generators/TestZip.zip | Bin 1670 -> 0 bytes 12 files changed, 76 insertions(+), 74 deletions(-) create mode 100644 Generators/Example06PostExec/Package.inf create mode 100644 Generators/Example06PostExec/Templates/Main.mako create mode 100644 Generators/Example07NumberLines/Package.inf rename Generators/{NumberLines => Example07NumberLines}/Templates/numberlines.mao (100%) create mode 100644 Generators/Example08Zip.zip delete mode 100644 Generators/NumberLines/Package.inf delete mode 100644 Generators/TestPostExec/Filters/Filter01.py delete mode 100644 Generators/TestPostExec/Package.inf delete mode 100644 Generators/TestPostExec/Templates/Main.mako delete mode 100644 Generators/TestPostExec/Templates/Sub.mako delete mode 100644 Generators/TestZip.zip diff --git a/Generators/Example06PostExec/Package.inf b/Generators/Example06PostExec/Package.inf new file mode 100644 index 0000000..50c7d64 --- /dev/null +++ b/Generators/Example06PostExec/Package.inf @@ -0,0 +1,24 @@ +[GENERATOR] +name = Example06PostExec +version = 1.0 +description = Example of the post execution feature +author = Joerg Raedler jraedler@udk-berlin.de + +[LOADER] +name = TestDummy +minVer = 0.1 +maxVer = 2.0 + +[MYCUSTOMSETTINGS] +answer = 42 + +# If a value for postExec is defined in a TEMPLATE section, the python command is executed +# right after the creation of the file. The variable fname contains the name of the +# generated file. This feature can be used to run a compiler on generated code or start +# other applications to process/copy/upload the generated file. +# Be VERY carefull with the postexec feature, it has complete access +# to the whole namespace and will run this code without checking! +[TEMPLATE] +topFile = Main.mako +type = mako +postExec = os.system("dir "+fname) diff --git a/Generators/Example06PostExec/Templates/Main.mako b/Generators/Example06PostExec/Templates/Main.mako new file mode 100644 index 0000000..1fa1983 --- /dev/null +++ b/Generators/Example06PostExec/Templates/Main.mako @@ -0,0 +1,36 @@ +# +# The following objects can be used in templates: +# +# systemCfg - dictionary with information on the system and the environment +# Keys: ${' '.join(systemCfg.keys())} +# CoTeToVersion: ${systemCfg['version']} +# CoTeToPath: ${systemCfg['path']} +# Platform: ${systemCfg['platform']} +# FullPlatform: ${systemCfg['fullplatform']} +# Hostname: ${systemCfg['hostname']} +# Username: ${systemCfg['username']} +# GeneratorPath: ${', '.join(systemCfg['generatorPath'])} +# +# the following are functions and need to be executed: +# Timestamp: ${systemCfg['timestamp']()} +# Infostamp: ${systemCfg['infostamp']()} +# +# generatorCfg - configparser object with information on the used generator +# (this is basically the contents of the Package.inf file) +# Sections: ${' '.join(generatorCfg.keys())} +# Name: ${generatorCfg['GENERATOR'].get('name')} +# Version: ${generatorCfg['GENERATOR'].get('version')} +# +# access to custom sections and values is also possible: +# Answer: ${generatorCfg['MYCUSTOMSETTINGS'].getint('answer')} +# +# logger - an object to send logging messages +# this will output None, but log a message: ${logger.info('The answer is 42!')} +# suppress the output with this trick: ${logger.warning('But what was the question?') or ''} +# +# d - the data object read from the loader and (optionally) manipulated by the filter +# (this is usually a dictionary of the form filename : data_items, +# but this depends on the loader and filter code) +# Keys (Filenames/URIs): ${' '.join(d.keys())} + +The value of foo is ${d['dummy']['foo']}. diff --git a/Generators/Example07NumberLines/Package.inf b/Generators/Example07NumberLines/Package.inf new file mode 100644 index 0000000..a8cb44b --- /dev/null +++ b/Generators/Example07NumberLines/Package.inf @@ -0,0 +1,14 @@ +[GENERATOR] +name = Example07NumberLines +version = 1.0 +description = Output the lines of the input text files with line numbers added +author = Joerg Raedler jraedler@udk-berlin.de + +[LOADER] +name = TextFile +minVer = 0.1 +maxVer = 2.0 + +[TEMPLATES] +topFile = numberlines.mao +type = mako diff --git a/Generators/NumberLines/Templates/numberlines.mao b/Generators/Example07NumberLines/Templates/numberlines.mao similarity index 100% rename from Generators/NumberLines/Templates/numberlines.mao rename to Generators/Example07NumberLines/Templates/numberlines.mao diff --git a/Generators/Example08Zip.zip b/Generators/Example08Zip.zip new file mode 100644 index 0000000000000000000000000000000000000000..1a1587479d5e31722df9d2c7751b14f468fb7cfe GIT binary patch literal 3512 zcmaJ@2|QGL6dq48cqFOFHd(SWlr1WQ!Hh6=qtFU-LWYJAhJ=}{p|ZSC zBC<5*kz{N2?4^k0jowr9UiI$%{qMQ={?0w$J?FdUo)2NhzD*FYx$O#0wD@xJ&jHA^ z##rA#Ou%VX#6Mm@z#e>}#WLRe=|MICK>HWwQ!HNQ#J~Mj2t?eaPQO;LAavREQ`-&4 zZQM{C*_3u?iZd`4vD6W+c3BU!gYt3hFc*Jq*=%%d_$Z+XP{23<)6aG$-3;m5$tx_C zM78iNs>y%fzCsP=7PPIKv>tin$pc6tLt4^-v{<0v;cfekMH-QPw<-C z{Z!{21xec{ui=Zf)d@(+3(w*2D0j(IG4D&)#Lw$ZOrLC2oSwjT^z0rqmZH7(b&uut z83?j6b*`8zZLZ>!Q0Vz1nBlK*H;qpAmE)q+7xrpRB5Fq+OlZrY*#I|{tX7Ga@dj3N zi_MYu-?8V)z3xi6CMuc(H2cUnH=muQFg`hbAAz6Vu~p;mnb_oKiwRd(0uhZudtqE% zSy(yFWFg? zUFbDGYq|37c$zq@UwZuRMJ*vVt@##A%0-O_lKpkpiDJLWWDC?B;u~jxPr*KEHXgdn z+oR;gj?ZB`uR<_08Lr$>q}9P$c1OoCXXJo|4kSLdhma=7x84_@cGGC8L!px3vqc6C5PDa**2!bCjGO_QS_hTZgGYaV>Eg^L1RY^ zGGToIwlWyzo$!7-BS?>$k;|ZBd?QtO?*^M^&#FC<3?JX;WHYvrKVLC3=lwcy>}2jL z`xb{l0Fv2Fzo^h`6xjg)I0pd0!(;@3Li?aRF)CO;51g$zegMqhWb!ad=-zhej?1lV z`}bRAC@cJFJ-{KYFPalt?LVDzN*C8w;o08f2e&IN(?s`XFOPPw$PYAe>qk|YfDMpd zxfe&VZ_tOx|wDFdC@-CPR_vu)WR4^m)xY~swbiJB*Q@SLSMIg^)xWB6@CjMq3zMmUjPxh zv3jr?kU8>ZFG$E}hHG~4YTtadsoXp&QnovPaeUTNBmI7o>7oMzf;9d0hJ#^uLGMXp z{%n-wzO`-#5&u~bLQFkN27(AS6I-RmkVnd@`K5$k3%3@GwMOfgc79aMi;56>`M!&z z$-XY_)=Eh5nI-@ATSRoe+b|alykk8x(gxL>y56D--N-PXdQjdzZ09+pmwIfrcIff( zM0y&+gz2wK4mJYVM%80?I0?s zQhUZ4A00!Y*R1ZO-ft9(H`W@C*eAwYVb@j?A66Z+ppH#ZE)yy08Wlb|+=;6+>)K5$ zG`R!LhD&nBaOvfBOP0dyki8yYJZA3hSqW zL;2t@+C}+11@o^*_01D}G-vd)TZdddj=h0D&FH^*Xzo-xSa5o>q)NszEjzkuzL})- z6h^;m0IXUXeMWz#OC&6K15#D^UzN!Xz&k_-W_BL*0igvvfVB`lgWv8~D`Y}RfJ=J4 zG~OFmAD!0bP*GP*cMs!LMD4wospza;&#_dSPC3U;8aYOZ5OC@gxE9p^<{j^#VAERT z$6b&^VYUYC&c*#{;6=iU7NW;Cp>#EQ7(uxpC-!!Kn74i5l;+CiC(&KiyyafCCZmsG zxo28uCEHw5noANXXg$MTES|h*C#;B!SH16gp-DUvkC-(~Vxu}$|&l;M^s*b$9| zgox^talM<+g&Yeay774D?GDA_QvQ~PaM7XA+pjsdS2+XOmvYsl)a?a*VuSpZ;aAu- zmV4`!PE?DU2<~}Bxr@rTtduveMh~m>^E8Xq&-x<8hVnkWjfglCa%FS`O1DbZOpZv@ z4W3@!z|@l}pI|OyyppET_99d`_*VaOS^I%E)K>1oeCzf&XblmMqLHL_?kL^bL5u;iRz1Y?lP}A=KYP z)S$Dd#5-g;Ad`6dFuT);8Ug2xcdhdmss9jEGafmevn`&yXwz4eRTvx`xjj-Tc{gM1 zCYsK}6OYx_=3~>G!^No@5Kad~gRwsn@fPXzIBsLklUALGR64% z;*~%!SsVxjIvwN&3jC)r_w#bQp#nfhK+@svCuH4&a5$o@^9fnzJz3{Sgc;i}#{fUm zpVCaE&5i$W^Hl?J13+KyumOYs&*PC3?h6BK|Fz#D|46fLMc#~afVsBR)mME)AhLp_ z^~)7F|1ZdoMB5g~=IbXgMcEbztAt}k`ELqa*Q}|0FZ8xhHdAT*3Ch>B{w@1h!H-`% zKl1-6{z%iXf?F{Ewk!&VHFy9h6^volZ_9q4+4uG125bf2tRICbp}u`|tg+Q*PJH!2Jaz`kbc# literal 0 HcmV?d00001 diff --git a/Generators/NumberLines/Package.inf b/Generators/NumberLines/Package.inf deleted file mode 100644 index 9b19271..0000000 --- a/Generators/NumberLines/Package.inf +++ /dev/null @@ -1,14 +0,0 @@ -[GENERATOR] -name = NumberLines -version = 0.1 -description = Output the lines of the input files with line numbers added -author = Jörg Rädler - -[LOADER] -name = TextFile -minVer = 0.1 -maxVer = 2.0 - -[TEMPLATES] -topFile = numberlines.mao -type = mako diff --git a/Generators/README.md b/Generators/README.md index fc29b30..f7a86e0 100644 --- a/Generators/README.md +++ b/Generators/README.md @@ -24,11 +24,11 @@ Two more folders are searched by default (if they exist): A generator may be: 1. a subfolder or -2. a zip file (not working correctly at the moment) +2. a zip file containing a file Package.inf and a special folder structure. -Documentation will follow soon, please have a look at the examples for now. The +Documentation may follow soon, please have a look at the examples for now. The easiest way to create a generator is to make a copy of an existing generator and adjust the contents. diff --git a/Generators/TestPostExec/Filters/Filter01.py b/Generators/TestPostExec/Filters/Filter01.py deleted file mode 100644 index d426454..0000000 --- a/Generators/TestPostExec/Filters/Filter01.py +++ /dev/null @@ -1,21 +0,0 @@ -# a filter function is called with the following arguments: -# d - the data dictionary read from the loader -# systemCfg - system configuration -# generatorCfg - generator configuration -# logger - a logger instance - - -def filter01(d, systemCfg, generatorCfg, logger): - - # spread a message - logger.debug('hi there! This is a filter running from module: ' + __file__) - - x = d['dummy'] - - # manipulate some data - x['foo'] += 1 - - # add more data - x['bar'] = 2.0 * x['foo'] - - # no return needed - data is manipulated inplace diff --git a/Generators/TestPostExec/Package.inf b/Generators/TestPostExec/Package.inf deleted file mode 100644 index f39e17f..0000000 --- a/Generators/TestPostExec/Package.inf +++ /dev/null @@ -1,22 +0,0 @@ -[GENERATOR] -name = TestPostExec -version = 0.1 -description = test the post execution feature -author = Joerg Raedler jraedler@udk-berlin.de - -[LOADER] -name = TestDummy -minVer = 0.1 -maxVer = 2.0 - -[FILTER] -module = Filter01 -function = filter01 - -[TEMPLATE] -topFile = Main.mako -type = mako -# be VERY carefull with the postexec feature, it has complete access -# to the whole namespace and will run this code without checking! -# You can use "fname" to access the name of the generated file -postExec = os.system("dir "+fname) diff --git a/Generators/TestPostExec/Templates/Main.mako b/Generators/TestPostExec/Templates/Main.mako deleted file mode 100644 index f282ca2..0000000 --- a/Generators/TestPostExec/Templates/Main.mako +++ /dev/null @@ -1,13 +0,0 @@ -# -# CoTeTo -# Info: ${systemCfg['infostamp']()} -# Path: ${systemCfg['path']} -# Gen-Path: ${', '.join(systemCfg['generatorPath'])} -# -# Generator -# Name: ${generatorCfg['GENERATOR'].get('name')} -# Version: ${generatorCfg['GENERATOR'].get('version')} - -The value of foo is ${d['dummy']['foo']}. - -<%include file="Sub.mako"/> diff --git a/Generators/TestPostExec/Templates/Sub.mako b/Generators/TestPostExec/Templates/Sub.mako deleted file mode 100644 index c082879..0000000 --- a/Generators/TestPostExec/Templates/Sub.mako +++ /dev/null @@ -1,2 +0,0 @@ -Hello, I'm a sub template! -bar = ${d['dummy']['bar']} diff --git a/Generators/TestZip.zip b/Generators/TestZip.zip deleted file mode 100644 index 44790b0302501023a70e425b7f7e2ce52cc761fb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1670 zcmWIWW@Zs#0D(EJ`QBg#l;8l;ZkahHsYS*50Z>&O3^&X2yje7}`3)Hv7%Z3=7=)2j zK~x(U>J?PxPV~%UG8AzAK5@t4{sQ(QlKK!cV_hI$P)LjVEQ>AAAit_$z$YR}cN~vMol>Ih*rX zjML`qOLO)V*ehEj*O`2^B7W`$s|0h#BQZv;_NTa87uh^W-hA}7@LY}Or~8-6$jssJ z{&{uY`&l!!9z1$|H6Z;pKO%&W0OMgp!qb^|fFWxQ3}tR09gvuuotU1gmzkFq+wbdr z#6Y0!edC|@KMcB8cPAunUbJQ1lm`coI_E6QzEd+%E$Q!9Yv1Zyx6d5@>Mn{txZ< z(uFVVH485>RVOel`?8Q(b-#f6TiHdsb}e=}XyPJ!sY__tj1=_(fz(eEGuvP9=gYam zmRBHGGh?Rw>AimQY*mex=gSAyeH8FtGkpP%%QxZc4-Hp;ek<;>ICg1+kXPT^g*QL0 z&fA^y)~EC8JK3je=S;1CT^4`!=pFm*i)LI~og-Gh-nS_tx#CRTje8R25i$pNZ{H>; zv-Sz|Gx4>PBh+su2%Jk)+-6hE2nz(v#K;8Z$38%9T8vv6d+yBE8w)k+Z-EE$`u;oFlRM6$#k4|gd`?{8JZj<3y z`d{wmxzi`rqIkof$1Id=KPbVlY);Urw|D02ugW@V#g`*Vji;uz&9*!C=YNad zmV!yz!u%J%+R1G?wDwWij)Yp92SS_tWnWv?u=LbL-aI)oaMDsQi*;gie_hzMcb-h1 zUv6>Yiw~~?-(*d?S+lLi-+tN*ch#MoQT>bZcSjxJeOG5WSB~vvSAueh^8q0h;}y5U zMI^;~4WrK(e_8my+!iWK!LG^N5 z*e!r;5EcSrM2G~JCV>OQBQ+-{Uq``HJy#)7p|~_jp#&PZio9G&iA4&w3M$np(dsFs zxw)0rF?mlnI%y3ZH^a2Y`M4TX-eSh~2u$eGANgl#Sm<8x%TQ zQOt(t0Ax${nYM#NXI?JEa2O4-1XnUbw&XZ7vIk&^3fYdf7>FG(kHF{vZ&o&-D;d~; M&=KfVeHIW80QtI5t^fc4 From f00e8cb760403e923e7fa3dd5e4d57ef0c1d3e72 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 15:00:49 +0200 Subject: [PATCH 11/15] ... --- .../Package.inf | 4 ++-- .../Templates/AncillaryCoefficients.mot | 0 .../Templates/AnnotationDocumentation.mot | 0 .../DynamicViscosityCoefficients.mot | 0 .../Templates/FluidConstants.mot | 0 .../Templates/FluidLimits.mot | 0 .../Templates/HelmholtzCoefficients.mot | 0 .../Templates/SurfaceTensionCoefficients.mot | 0 .../ThermalConductivityCoefficients.mot | 0 .../Templates/package.mot | 0 Generators/Example51XML/Package.inf | 13 +++++++++++ .../Templates/Main.tmpl | 0 Generators/TestXML/Package.inf | 13 ----------- foo | 22 ------------------- 14 files changed, 15 insertions(+), 37 deletions(-) rename Generators/{JsonFluid => Example50JsonFluid}/Package.inf (89%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/AncillaryCoefficients.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/AnnotationDocumentation.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/DynamicViscosityCoefficients.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/FluidConstants.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/FluidLimits.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/HelmholtzCoefficients.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/SurfaceTensionCoefficients.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/ThermalConductivityCoefficients.mot (100%) rename Generators/{JsonFluid => Example50JsonFluid}/Templates/package.mot (100%) create mode 100644 Generators/Example51XML/Package.inf rename Generators/{TestXML => Example51XML}/Templates/Main.tmpl (100%) delete mode 100644 Generators/TestXML/Package.inf delete mode 100644 foo diff --git a/Generators/JsonFluid/Package.inf b/Generators/Example50JsonFluid/Package.inf similarity index 89% rename from Generators/JsonFluid/Package.inf rename to Generators/Example50JsonFluid/Package.inf index 360ee58..dbb6b68 100644 --- a/Generators/JsonFluid/Package.inf +++ b/Generators/Example50JsonFluid/Package.inf @@ -1,6 +1,6 @@ [GENERATOR] -name = JsonFluid -version = 0.1 +name = Example50JsonFluid +version = 1.0 description = Reads information about Equations of States for fluids from CoolProp json file and generates HelmholtzMedia Modelica input files. author = Matthis Thorade diff --git a/Generators/JsonFluid/Templates/AncillaryCoefficients.mot b/Generators/Example50JsonFluid/Templates/AncillaryCoefficients.mot similarity index 100% rename from Generators/JsonFluid/Templates/AncillaryCoefficients.mot rename to Generators/Example50JsonFluid/Templates/AncillaryCoefficients.mot diff --git a/Generators/JsonFluid/Templates/AnnotationDocumentation.mot b/Generators/Example50JsonFluid/Templates/AnnotationDocumentation.mot similarity index 100% rename from Generators/JsonFluid/Templates/AnnotationDocumentation.mot rename to Generators/Example50JsonFluid/Templates/AnnotationDocumentation.mot diff --git a/Generators/JsonFluid/Templates/DynamicViscosityCoefficients.mot b/Generators/Example50JsonFluid/Templates/DynamicViscosityCoefficients.mot similarity index 100% rename from Generators/JsonFluid/Templates/DynamicViscosityCoefficients.mot rename to Generators/Example50JsonFluid/Templates/DynamicViscosityCoefficients.mot diff --git a/Generators/JsonFluid/Templates/FluidConstants.mot b/Generators/Example50JsonFluid/Templates/FluidConstants.mot similarity index 100% rename from Generators/JsonFluid/Templates/FluidConstants.mot rename to Generators/Example50JsonFluid/Templates/FluidConstants.mot diff --git a/Generators/JsonFluid/Templates/FluidLimits.mot b/Generators/Example50JsonFluid/Templates/FluidLimits.mot similarity index 100% rename from Generators/JsonFluid/Templates/FluidLimits.mot rename to Generators/Example50JsonFluid/Templates/FluidLimits.mot diff --git a/Generators/JsonFluid/Templates/HelmholtzCoefficients.mot b/Generators/Example50JsonFluid/Templates/HelmholtzCoefficients.mot similarity index 100% rename from Generators/JsonFluid/Templates/HelmholtzCoefficients.mot rename to Generators/Example50JsonFluid/Templates/HelmholtzCoefficients.mot diff --git a/Generators/JsonFluid/Templates/SurfaceTensionCoefficients.mot b/Generators/Example50JsonFluid/Templates/SurfaceTensionCoefficients.mot similarity index 100% rename from Generators/JsonFluid/Templates/SurfaceTensionCoefficients.mot rename to Generators/Example50JsonFluid/Templates/SurfaceTensionCoefficients.mot diff --git a/Generators/JsonFluid/Templates/ThermalConductivityCoefficients.mot b/Generators/Example50JsonFluid/Templates/ThermalConductivityCoefficients.mot similarity index 100% rename from Generators/JsonFluid/Templates/ThermalConductivityCoefficients.mot rename to Generators/Example50JsonFluid/Templates/ThermalConductivityCoefficients.mot diff --git a/Generators/JsonFluid/Templates/package.mot b/Generators/Example50JsonFluid/Templates/package.mot similarity index 100% rename from Generators/JsonFluid/Templates/package.mot rename to Generators/Example50JsonFluid/Templates/package.mot diff --git a/Generators/Example51XML/Package.inf b/Generators/Example51XML/Package.inf new file mode 100644 index 0000000..7a4a3c4 --- /dev/null +++ b/Generators/Example51XML/Package.inf @@ -0,0 +1,13 @@ +[GENERATOR] +name = Example51XML +version = 1.0 +description = Example of the XMLFile loader - please load "test/TestXML.xml,test/TestXML1.xsd,/TestXML2.xsd" as input, +author = Werner Kaul we.kaul@udk-berlin.de + +[LOADER] +name = XMLFile +minVer = 0.1 +maxVer = 2.0 + +[TEMPLATE] +topFile = Main.tmpl diff --git a/Generators/TestXML/Templates/Main.tmpl b/Generators/Example51XML/Templates/Main.tmpl similarity index 100% rename from Generators/TestXML/Templates/Main.tmpl rename to Generators/Example51XML/Templates/Main.tmpl diff --git a/Generators/TestXML/Package.inf b/Generators/TestXML/Package.inf deleted file mode 100644 index f747dfd..0000000 --- a/Generators/TestXML/Package.inf +++ /dev/null @@ -1,13 +0,0 @@ -[GENERATOR] -name = TestXML -version = 0.1 -description = test XMLFile loader - please load "test/TestXML.xml,test/TestXML1.xsd,/TestXML2.xsd" as input, -author = Werner Kaul we.kaul@udk-berlin.de - -[LOADER] -name = XMLFile -minVer = 0.1 -maxVer = 2.0 - -[TEMPLATE] -topFile = Main.tmpl diff --git a/foo b/foo deleted file mode 100644 index 28c668a..0000000 --- a/foo +++ /dev/null @@ -1,22 +0,0 @@ -# -# CoTeTo -# Version: 0.99 -# Platform: win32 -# Path: C:\Users\jraedler\Devel\CoTeTo\CoTeTo -# Gen-Path: C:\Users\jraedler\Devel\CoTeTo\Generators, C:\Users\jraedler\Devel\CoTeTo_Generators -# -# Generator -# Name: Example05CustomLoaders -# Version: 1.0 - -File: C:/Users/jraedler/Devel/CoTeTo/test/custom.txt - Key: "foo" - Value: "bar" - - Key: "x" - Value: "y:z" - - Key: "spam" - Value: "eggs" - - From 1709e793fbb8ab9113526d5819d62be2d85c36ab Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 15:05:04 +0200 Subject: [PATCH 12/15] preparing for version 1.0 --- CoTeTo/__init__.py | 3 ++- setup.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CoTeTo/__init__.py b/CoTeTo/__init__.py index bccc1ef..1d73c9a 100644 --- a/CoTeTo/__init__.py +++ b/CoTeTo/__init__.py @@ -6,9 +6,10 @@ import sys -__version__ = '0.99' +__version__ = '1.0' # special hack for mako on windows to correct a nasty line ending problem +# FIXME: is this still needed? if sys.platform.startswith('win'): def read_file(path, mode='r'): fp = open(path, mode) diff --git a/setup.py b/setup.py index ba9047f..309add1 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='CoTeTo', - version='0.99', + version='1.0', description='Code Templating Tool - code generation framework based on templates', author='Joerg Raedler (UdK Berlin)', author_email='jraedler@udk-berlin.de', From 74a6a76a979766295bb7cbd2c816a132ab342290 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 16:25:18 +0200 Subject: [PATCH 13/15] small changes to the scripts, add module example --- scripts/CoTeTo-cli.py | 3 +++ scripts/CoTeTo-gui.py | 3 +++ scripts/CoTeTo-module.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 scripts/CoTeTo-module.py diff --git a/scripts/CoTeTo-cli.py b/scripts/CoTeTo-cli.py index c4aec29..5462f21 100644 --- a/scripts/CoTeTo-cli.py +++ b/scripts/CoTeTo-cli.py @@ -4,6 +4,9 @@ # This file is part of CoTeTo - a code generation tool # 20170602 Joerg Raedler jraedler@udk-berlin.de # +# This is the commandline interface to CoTeTo. +# Run `python CoTeTo-cli.py --help` to get help on the +# commandline options and arguements import os import sys diff --git a/scripts/CoTeTo-gui.py b/scripts/CoTeTo-gui.py index d605ecc..e205e33 100644 --- a/scripts/CoTeTo-gui.py +++ b/scripts/CoTeTo-gui.py @@ -4,6 +4,9 @@ # This file is part of CoTeTo - a code generation tool # 20170602 Joerg Raedler jraedler@udk-berlin.de # +# This is the graphical user interface to CoTeTo. +# Run `python CoTeTo-gui.py --help` to get help on the +# commandline options and arguements import os import sys diff --git a/scripts/CoTeTo-module.py b/scripts/CoTeTo-module.py new file mode 100644 index 0000000..267d5c3 --- /dev/null +++ b/scripts/CoTeTo-module.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +# +# This file is part of CoTeTo - a code generation tool +# 20190411 Joerg Raedler jraedler@udk-berlin.de +# +# This is an example of the usage of CoTeTo as a python module. +# + +import os +import sys + +# check if we are running in the development folder - +# just a hack to run this script without installing CoTeTo first - +# usually not needed for users +parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +if os.path.isfile(os.path.join(parent, 'setup.py')): + sys.path.insert(0, parent) + +#### Example Code + +# 1. import the controller class from CoTeTo +from CoTeTo.Controller import Controller + +# 2. initialize a controller instance +# for a list of optional arguments see CoTeTo/Controller.py +con = Controller() + +# 3. choose a generator ... +# a list of available generators can be printed with print(con.generators.keys()) +gen = con.generators['Example01Mako::1.0'] + +# 4. ... and execute it! +# arguments are: +# a list of input URIs (not used with the dummy loader) +# a filename or prefix for the output +gen.execute(('spam', ), 'ModuleTestOutput.txt') From ebef15aa39925869532def8777e4b3139221a8e3 Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 16:27:43 +0200 Subject: [PATCH 14/15] ... --- scripts/CoTeTo-module.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/CoTeTo-module.py b/scripts/CoTeTo-module.py index 267d5c3..d305e90 100644 --- a/scripts/CoTeTo-module.py +++ b/scripts/CoTeTo-module.py @@ -7,12 +7,10 @@ # This is an example of the usage of CoTeTo as a python module. # -import os -import sys - # check if we are running in the development folder - # just a hack to run this script without installing CoTeTo first - # usually not needed for users +import os, sys parent = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) if os.path.isfile(os.path.join(parent, 'setup.py')): sys.path.insert(0, parent) @@ -27,7 +25,7 @@ con = Controller() # 3. choose a generator ... -# a list of available generators can be printed with print(con.generators.keys()) +# (get a list of available generators with print(con.generators.keys())) gen = con.generators['Example01Mako::1.0'] # 4. ... and execute it! From fbf69c39a5791f98d871a1466d867f2e66062b8f Mon Sep 17 00:00:00 2001 From: Joerg Raedler Date: Thu, 11 Apr 2019 16:57:14 +0200 Subject: [PATCH 15/15] add lxml dependency --- README.md | 2 ++ tools/dependency_check.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 36ee6b3..3911015 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ install it by running `pip install -U mako` on a Python-enabled command prompt 4. If you are not using WinPython, you also need to install the Jinja2 templating engine by running `pip install -U jinja2` on a Python-enabled command prompt +5. If you want to use the XML loader you need to install the lxml package: +`pip install -U lxml`. You can check these dependencies by running the script `tools/dependency_check.py` if you already have a python interpreter installed. diff --git a/tools/dependency_check.py b/tools/dependency_check.py index 71a25a6..8729cfe 100644 --- a/tools/dependency_check.py +++ b/tools/dependency_check.py @@ -64,4 +64,13 @@ def done(status=0): l.append('- GUI will not run, please install PyQt5 and retry!') lb.append(l) +# Checking lxml +l = ['Checking lxml... '] +try: + from lxml import etree, objectify + l.append('Ok!') +except BaseException: + l.append('- XML loader will not run, you should install lxml and retry!') +lb.append(l) + done(0)