summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2020-11-04 16:19:12 +0100
committerDominik Holland <dominik.holland@qt.io>2020-12-14 17:21:28 +0100
commitb93f8aba16a4294c4848412fb7718038a2c36f67 (patch)
tree60238bb4062967ef5f890ddeef58def5d6abe092 /src
parente1e92987e999bc8fd463f05d6945c2ae25ffc026 (diff)
downloadqtivi-b93f8aba16a4294c4848412fb7718038a2c36f67.tar.gz
Add support for custom filters per template
If the ivigenerator finds a filters.py file within the currently used template folder, this filters.py is loaded in addition to the already registered filters from the ivigenerator. It is also possible to import the original ivigenerator python files from the custom filters.py and reuse existing functionality. Fixes: AUTOSUITE-860 Change-Id: I7769255f1d55353a940347bab18b6b327214bb96 Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/tools/ivigenerator/generate.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py
index ba6c213..f1cdb90 100755
--- a/src/tools/ivigenerator/generate.py
+++ b/src/tools/ivigenerator/generate.py
@@ -48,6 +48,7 @@ from path import Path
from qface.generator import FileSystem, Generator
from qface.watch import monitor
+from qface.utils import load_filters
import generator.builtin_config as builtin_config
import generator.global_functions as global_functions
@@ -124,6 +125,17 @@ def generate(tplconfig, moduleConfig, annotations, imports, src, dst):
global_functions.register_global_functions(generator)
register_filters(generator)
+ # Add the current path to the module search path
+ # This makes it possible to import our filters.py and friends
+ # from the plugin filters
+ sys.path.append(os.path.join(os.path.dirname(__file__)))
+
+ # Add a module specific extra filter if found
+ extra_filter_path = os.path.dirname(tplconfig) + '/{0}/filters.py'.format(os.path.basename(tplconfig))
+ if os.path.exists(extra_filter_path):
+ extra_filters = load_filters(Path(extra_filter_path))
+ generator.filters = extra_filters
+
validateSystem(srcFile, system)
# Make sure the config tag is available for all our symbols