Created
December 14, 2015 14:12
-
-
Save Jonty/e2a42d286ceb457cfa28 to your computer and use it in GitHub Desktop.
Converts from cf job spec properties format to something usable with a normal manifest. Horrendous.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import yaml | |
import re | |
import textwrap | |
data = {} | |
for k, v in yaml.load(sys.stdin.read())['properties'].items(): | |
prev = data | |
bits = k.split('.') | |
for name in bits[:-1]: | |
if name not in prev: | |
prev[name] = {} | |
prev = prev[name] | |
prev[bits[-1]] = v | |
def format(key, items, indent): | |
if ('default' in items) or (len(items) == 1 and 'description' in items): | |
if items.get('description'): | |
description = '\n'.join(textwrap.wrap(items['description'], 80)) | |
print re.sub('^', ' ' * indent + '# ', description, flags=re.MULTILINE) | |
print "%s%s: %s" % (' ' * indent, key, items.get('default', '~')) | |
return | |
print "%s%s:" % (' ' * indent, key) | |
for k, v in items.items(): | |
if isinstance(v, dict): | |
format(k, v, indent+1) | |
format("properties", data, 0) |
The spruce merge all is a bit dangerous as many times jobs have the same property (e.g. password) and they get overridden. It would be good to write a test to compare if the same job properties (properties with same names between multiple jobs) share same default value or not.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To generate the input from a CF release: