Skip to content

Commit

Permalink
fixed python2 and 3 compatibility issues w docker-quickstart scripts (#…
Browse files Browse the repository at this point in the history
…2618)

* fixed python2 and 3 compatibility issues

---------

Co-authored-by: Moriarty <[email protected]>
  • Loading branch information
skyler-kv and apmoriarty authored Oct 30, 2024
1 parent 3d7d40d commit 38d6ac3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
17 changes: 2 additions & 15 deletions contrib/datawave-quickstart/bin/query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,8 @@ function setQueryIdFromResponse() {
}

function prettyPrintJson() {
local PY=$( which python )
if [ -n "${PY}" ] ; then
echo "${1}" | ${PY} -c 'from __future__ import print_function;import sys,json;data=json.loads(sys.stdin.read()); print(json.dumps(data, indent=2, sort_keys=True))'
local exitStatus=$?
echo
if [ "${exitStatus}" != "0" ] ; then
printRawResponse "${1}"
warn "Python encountered error. Printed response without formatting"
echo
fi
else
printRawResponse "${1}"
warn "Couldn't find python in your environment. Json response was printed without formatting"
echo
fi
PY_CMD='from __future__ import print_function; import sys,json; data=json.loads(sys.stdin.read()); print(json.dumps(data, indent=2, sort_keys=True))'
echo "${1}" | ( python3 -c "${PY_CMD}" 2>/dev/null || python2 -c "${PY_CMD}" 2>/dev/null ) || ( warn "Python encountered error. Printed response without formatting" && printRawResponse "${1}" )
}

function printRawResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ TVMAZE_RESPONSE_STATUS=$( echo ${CURL_RESPONSE} | tr -d '\n' | sed -e 's/.*HTTP_
[ "${TVMAZE_RESPONSE_STATUS}" != "200" ] && error "api.tvmaze.com returned invalid response status: ${TVMAZE_RESPONSE_STATUS}" && exit 1
[ -z "${TVMAZE_RESPONSE_BODY}" ] && error "Response body is empty!" && exit 1

PY_CMD='from __future__ import print_function; import sys,json; data=json.loads(sys.stdin.read()); print(json.dumps(data, indent=2, sort_keys=True))'
if [ "${PRETTY}" == true ] ; then
echo "${TVMAZE_RESPONSE_BODY}" | python -c 'from __future__ import print_function;import sys,json;data=json.loads(sys.stdin.read()); print(json.dumps(data, indent=2, sort_keys=True))'
echo "${TVMAZE_RESPONSE_BODY}" | ( python3 -c "${PY_CMD}" 2>/dev/null || python2 -c "${PY_CMD}" 2>/dev/null ) || ( warn "Unable to pretty print, Python not detected" && echo "${TVMAZE_RESPONSE_BODY}" )
else
echo "${TVMAZE_RESPONSE_BODY}"
echo "${TVMAZE_RESPONSE_BODY}"
fi

exit 0
2 changes: 1 addition & 1 deletion contrib/datawave-quickstart/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ COPY . /opt/datawave

# Install dependencies, configure password-less/zero-prompt SSH...

RUN dnf -y install gcc-c++ openssl openssh openssh-server openssh-clients openssl-libs which bc wget git java-11-openjdk-devel iproute && \
RUN dnf -y install gcc-c++ openssl python3 openssh openssh-server openssh-clients openssl-libs which bc wget git java-11-openjdk-devel iproute && \
dnf clean all && \
ssh-keygen -q -N "" -t rsa -f ~/.ssh/id_rsa && \
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys && \
Expand Down

0 comments on commit 38d6ac3

Please sign in to comment.