diff options
author | Fathi Boudra <fathi.boudra@linaro.org> | 2017-01-13 11:41:04 +0200 |
---|---|---|
committer | Fathi Boudra <fathi.boudra@linaro.org> | 2017-01-13 11:44:49 +0200 |
commit | 1ed4330773cee3e848160267219c7e54ede714d0 (patch) | |
tree | 95e459ec164d0ecc7beaec7574d41bb7b5189617 | |
parent | 175a5268a52ccea0851201bd256325e022e020fe (diff) |
Revert "Refactored yaml-to-json script"
This reverts commit 175a5268a52ccea0851201bd256325e022e020fe.
It's causing failure with existing jobs:
Traceback (most recent call last):
File "./lci-build-tools/yaml-to-json.py", line 24, in <module>
main()
File "./lci-build-tools/yaml-to-json.py", line 16, in main
lava_template = template_replace(template)
File "<https://ci.linaro.org/jenkins/job/96boards-reference-platform-openembedded-morty/DISTRO=rpb,MACHINE=dragonboard-410c,label=docker-jessie-amd64/ws/lci-build-tools/yamljsonlib/__init__.py",> line 8, in template_replace
placeholders = set(filter(None, itertools.chain(*placeholders)))
NameError: global name 'itertools' is not defined
Change-Id: I2287bba12ed8df67f87097d033115e436f08fb9b
-rwxr-xr-x | prepare-template.py | 15 | ||||
-rwxr-xr-x | yaml-to-json.py | 15 | ||||
-rw-r--r-- | yamljsonlib/__init__.py | 17 |
3 files changed, 13 insertions, 34 deletions
diff --git a/prepare-template.py b/prepare-template.py deleted file mode 100755 index aa27d38..0000000 --- a/prepare-template.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python - -import sys -from yamljsonlib import template_replace - - -def main(): - with open(sys.argv[1]) as f: - template = string.Template(f.read()) - lava_template = template_replace(template) - print lava_template - - -if __name__ == '__main__': - main() diff --git a/yaml-to-json.py b/yaml-to-json.py index c087d81..4da2eae 100755 --- a/yaml-to-json.py +++ b/yaml-to-json.py @@ -2,18 +2,29 @@ import itertools import json +import os import string import sys import yaml -from yamljsonlib import template_replace # Find all placeholders in the input and replace them with the values of # equivalently-named environment variables. def main(): with open(sys.argv[1]) as f: template = string.Template(f.read()) - lava_template = 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) # FIXME: use ordered dictionaries - see http://pyyaml.org/ticket/29 config = json.dumps(yaml.safe_load(lava_template), indent=2, separators=(',', ': ')) diff --git a/yamljsonlib/__init__.py b/yamljsonlib/__init__.py deleted file mode 100644 index 4b12525..0000000 --- a/yamljsonlib/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -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 |