From 3388e470b8b31d16f130dcc3bcaa35f31fff6153 Mon Sep 17 00:00:00 2001 From: Ivan Kadochnikov Date: Tue, 13 Sep 2016 03:33:27 +1000 Subject: [PATCH] Minimize python use when replacing configs --- bootstrap-salt.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index b13b7c8..a3d6cd8 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1901,17 +1901,14 @@ __overwriteconfig() { # Convert json string to a yaml string and write it to config file. Output is dumped into tempfile. python -c "import json; import yaml; jsn=json.loads('$json'); yml=yaml.safe_dump(jsn, line_break='\n', default_flow_style=False); config_file=open('$target', 'w'); config_file.write(yml); config_file.close();" 2>$tempfile - # Check if there were any errors output to the tempfile - filesize=$(python -c "import os; print os.stat('$tempfile').st_size;") - # No python errors output to the tempfile - if [ "$filesize" -eq 0 ]; then + if [ ! -s "$tempfile" ]; then rm -f "$tempfile" return 0 fi - # Errors are present in the tempfile - let's expose the that to the user. - fullerror=$(python -c "tmp_file=open('$tempfile'); print tmp_file.read(); tmp_file.close()") + # Errors are present in the tempfile - let's expose them to the user. + fullerror=$(cat "$tempfile") echodebug "$fullerror" echoerror "Python error encountered. This is likely due to passing in a malformed JSON string. Please use -D to see stacktrace."