summaryrefslogtreecommitdiff
path: root/yamljsonlib/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'yamljsonlib/__init__.py')
-rw-r--r--yamljsonlib/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/yamljsonlib/__init__.py b/yamljsonlib/__init__.py
new file mode 100644
index 0000000..4b12525
--- /dev/null
+++ b/yamljsonlib/__init__.py
@@ -0,0 +1,17 @@
+import os
+import string
+
+
+def template_replace(template):
+ placeholders = map(lambda match: match.group('named', 'braced'),
+ string.Template.pattern.finditer(template.template))
+ placeholders = set(filter(None, itertools.chain(*placeholders)))
+
+ # Pretend that missing environment variables are set to empty strings.
+ # It would be better to throw an error on missing environment variables,
+ # but this doesn't play nicely with Jenkins. When Jenkins adds parameters to
+ # a triggered job via a properties file, any parameters explicitly set to
+ # the empty string will be unset in the environment of the downstream job.
+ substitutions = {x: os.environ.get(x) or '' for x in placeholders}
+ lava_template = template.safe_substitute(substitutions)
+ return lava_template