Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed python2 and 3 compatibility issues w docker-quickstart scripts #2618

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"'
foster33 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading