|
|
@@ -49,6 +49,12 @@ def ask_config_opt(config, key): |
|
|
|
|
|
|
|
config[key] = val |
|
|
|
|
|
|
|
def apply_template_settings(tmplt, settings): |
|
|
|
cur = tmplt |
|
|
|
for k, v in settings.items(): |
|
|
|
cur = cur.replace('${' + k + '}', v) |
|
|
|
return cur |
|
|
|
|
|
|
|
USAGE_STR = 'usage: yarrbox.py <init|edit|generate>' |
|
|
|
|
|
|
|
def main(): |
|
|
@@ -65,15 +71,23 @@ def main(): |
|
|
|
print('') |
|
|
|
|
|
|
|
# Write it to file |
|
|
|
with open('config.json', 'w') as f: |
|
|
|
f.write(json.dumps(cfg)) |
|
|
|
try: |
|
|
|
with open('config.json', 'w') as f: |
|
|
|
f.write(json.dumps(cfg)) |
|
|
|
except e: |
|
|
|
print('error writing config, do we have write perms?', e) |
|
|
|
return |
|
|
|
|
|
|
|
elif command == 'edit': |
|
|
|
print('Leave options blank to leave unchanged!\n') |
|
|
|
# Read the file. |
|
|
|
cfg = None |
|
|
|
with open('config.json', 'r') as f: |
|
|
|
cfg = json.loads(f.read()) |
|
|
|
try: |
|
|
|
with open('config.json', 'r') as f: |
|
|
|
cfg = json.loads(f.read()) |
|
|
|
except e: |
|
|
|
print('error loading config, is it missing or corrupt?', e) |
|
|
|
return |
|
|
|
|
|
|
|
# Go through all the properties again and reread them. |
|
|
|
for k in PROPS: |
|
|
@@ -81,9 +95,38 @@ def main(): |
|
|
|
print('') |
|
|
|
|
|
|
|
# Write it back. |
|
|
|
with open('config.json', 'w') as f: |
|
|
|
f.write(json.dumps(cfg)) |
|
|
|
|
|
|
|
try: |
|
|
|
with open('config.json', 'w') as f: |
|
|
|
f.write(json.dumps(cfg)) |
|
|
|
except e: |
|
|
|
print('error writing config, do we have write perms?', e) |
|
|
|
return |
|
|
|
|
|
|
|
elif command == 'generate': |
|
|
|
# Load the config. |
|
|
|
cfg = None |
|
|
|
try: |
|
|
|
with open('config.json', 'r') as f: |
|
|
|
cfg = json.loads(f.read()) |
|
|
|
except e: |
|
|
|
print('error loading config, is it missing or corrupt?', e) |
|
|
|
return |
|
|
|
|
|
|
|
tmplt = None |
|
|
|
try: |
|
|
|
with open('compose-template.yml', 'r') as f: |
|
|
|
tmplt = f.read() |
|
|
|
except e: |
|
|
|
print('error reading template:', e) |
|
|
|
return |
|
|
|
|
|
|
|
gen = apply_template_settings(tmplt, cfg) |
|
|
|
try: |
|
|
|
with open('docker-compose.yml', 'w') as f: |
|
|
|
f.write(gen) |
|
|
|
except e: |
|
|
|
print('error writing generated file, do we have write perms?', e) |
|
|
|
return |
|
|
|
else: |
|
|
|
print(USAGE_STR) |
|
|
|
|