feat: add support for python3

- Use jq where possible
- Drop unused function (no usage across entire codebase nor in any github repository

Closes #3689
This commit is contained in:
Jose Diaz-Gonzalez
2019-09-17 03:06:00 -04:00
parent 7bd4d32cb3
commit b4e95fe0d5
9 changed files with 20 additions and 26 deletions

View File

@@ -17,7 +17,7 @@ get_phase_script() {
return 0
fi
get_json_value "scripts.dokku.${PHASE_SCRIPT_KEY}" <"$APP_JSON_FILE"
get_json_value ".scripts.dokku.${PHASE_SCRIPT_KEY}" <"$APP_JSON_FILE"
}
get_release_cmd() {

View File

@@ -923,24 +923,10 @@ internal_get_app_urls() {
get_json_value() {
declare desc="return value of provided json key from a json stream on stdin"
# JSON_NODE should be expresses as either a top-level object that has no children
# or in the format of json.node.path
# or in the format of .json.node.path
local JSON_NODE="$1"
local JSON_NODE=${JSON_NODE//\./\"][\"}
local JSON_NODE="[\"${JSON_NODE}\"]"
cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj'"${JSON_NODE}"').strip("\"")'
}
get_json_keys() {
declare desc="return space-separated list of json keys from json provided on stdin"
# JSON_NODE should be expressed as json.node.path and is expected to have children
local JSON_NODE="$1"
local JSON_NODE=${JSON_NODE//\./\"][\"}
local JSON_NODE="[\"${JSON_NODE}\"]"
if [[ "$JSON_NODE" == "[\"\"]" ]]; then
cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj.keys())'
else
cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj'"${JSON_NODE}"'.keys())'
fi
cat | jq -r "${JSON_NODE} | select (.!=null)" 2>/dev/null
}
strip_inline_comments() {

View File

@@ -40,7 +40,7 @@ for container in data:
container['Config']['Env'] = env
output.append(container)
print json.dumps(data, sort_keys=True, indent=4)
print(json.dumps(data, sort_keys=True, indent=4))
EOF
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 2 -n | xargs)"