mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00

Up until now I didn't see the point of using spaces for indentation. However, the previous commit (a18bec3) was quite eye opening. Given that python is an indentation aware language, the amount of mistakes that went unnoticed because tabs and spaces were used at the same time (tabs for indentation and spaces for alignment) were unacceptable. E101,W191 have been re-enable in the tox flake8 checker and the documentation has been modified accordingly. The following files have been left as-is: * bootstrapvz/common/assets/extlinux/extlinux.conf * bootstrapvz/common/assets/init.d/expand-root * bootstrapvz/common/assets/init.d/generate-ssh-hostkeys * bootstrapvz/common/assets/init.d/squeeze/generate-ssh-hostkeys * bootstrapvz/plugins/docker_daemon/assets/init.d/docker * bootstrapvz/providers/ec2/assets/bin/growpart * bootstrapvz/providers/ec2/assets/grub.d/40_custom * bootstrapvz/providers/ec2/assets/init.d/ec2-get-credentials * bootstrapvz/providers/ec2/assets/init.d/ec2-run-user-data * docs/_static/taskoverview.coffee * docs/_static/taskoverview.less * tests/unit/subprocess.sh
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
import os.path
|
|
import glob
|
|
import random
|
|
import string
|
|
from bootstrapvz.common.tools import load_data
|
|
|
|
partial_json = glob.glob(os.path.join(os.path.dirname(__file__), '*.yml'))
|
|
partial_yaml = glob.glob(os.path.join(os.path.dirname(__file__), '*.json'))
|
|
|
|
partials = {}
|
|
for path in partial_json + partial_yaml:
|
|
key = os.path.splitext(os.path.basename(path))[0]
|
|
if key in partials:
|
|
msg = 'Error when loading partial manifests: The partial {key} exists twice'.format(key=key)
|
|
raise Exception(msg)
|
|
partials[key] = load_data(path)
|
|
|
|
pool = string.ascii_uppercase + string.ascii_lowercase + string.digits
|
|
random_password = ''.join(random.choice(pool) for _ in range(16))
|
|
partials['root_password']['plugins']['root_password']['password'] = random_password
|
|
|
|
|
|
def merge_manifest_data(standard_partials=[], custom=[]):
|
|
import yaml
|
|
manifest_data = [partials[name] for name in standard_partials]
|
|
manifest_data.extend(yaml.load(data) for data in custom)
|
|
return merge_dicts(*manifest_data)
|
|
|
|
|
|
# Snatched from here: http://stackoverflow.com/a/7205107
|
|
def merge_dicts(*args):
|
|
def clone(obj):
|
|
copy = obj
|
|
if isinstance(obj, dict):
|
|
copy = {key: clone(value) for key, value in obj.iteritems()}
|
|
if isinstance(obj, list):
|
|
copy = [clone(value) for value in obj]
|
|
if isinstance(obj, set):
|
|
copy = set([clone(value) for value in obj])
|
|
return copy
|
|
|
|
def merge(a, b, path=[]):
|
|
for key in b:
|
|
if key in a:
|
|
if isinstance(a[key], dict) and isinstance(b[key], dict):
|
|
merge(a[key], b[key], path + [str(key)])
|
|
elif a[key] == b[key]:
|
|
pass
|
|
else:
|
|
raise Exception('Conflict at `{path}\''.format(path='.'.join(path + [str(key)])))
|
|
else:
|
|
a[key] = clone(b[key])
|
|
return a
|
|
return reduce(merge, args, {})
|