Skip to content

Commit

Permalink
Merge pull request #36 from cp2boston/develop
Browse files Browse the repository at this point in the history
RCB-357 Updated script to detect exceptions
  • Loading branch information
cp2boston committed Mar 28, 2016
2 parents 9da71bf + 3720a2c commit a6368c5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 75 deletions.
4 changes: 0 additions & 4 deletions CHANGES.txt

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include README.md CHANGES.txt LICENSE.txt
include README.md LICENSE.txt
exclude MANIFEST.in
98 changes: 65 additions & 33 deletions docker/run_python.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash

retcode=0
ping_url="https://api.rosette.com/rest/v1"

#------------------ Functions ----------------------------------------------------
#Gets called when the user doesn't provide any args
function HELP {
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
echo -e "\nusage: --key API_KEY [--FILENAME filename] [--url ALT_URL]"
echo " API_KEY - Rosette API key (required)"
echo " FILENAME - Python source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
Expand All @@ -12,6 +16,58 @@ function HELP {
exit 1
}

#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}

function cleanURL() {
# strip the trailing slash off of the alt_url if necessary
if [ ! -z "${ALT_URL}" ]; then
case ${ALT_URL} in
*/) ALT_URL=${ALT_URL::-1}
echo "Slash detected"
;;
esac
ping_url=${ALT_URL}
fi
}

function validateURL() {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
if [ "${match}" = "" ]; then
echo -e "\n${ping_url} server not responding\n"
exit 1
fi
}

function runExample() {
echo -e "\n---------- ${1} start -------------"
result=""
if [ -z ${ALT_URL} ]; then
result="$(python ${1} --key ${API_KEY} 2>&1 )"
else
result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )"
fi
echo "${result}"
echo -e "\n---------- ${1} end -------------"
if [[ "${result}" == *"Exception"* ]]; then
echo "Exception found"
retcode=1
elif [[ "$result" == *"processingFailure"* ]]; then
retcode=1
elif [[ "$result" == *"AttributeError"* ]]; then
retcode=1
elif [[ "$result" == *"ImportError"* ]]; then
retcode=1
fi
}
#------------------ Functions End ------------------------------------------------

#Gets API_KEY, FILENAME and ALT_URL if present
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
case "${arg}" in
Expand All @@ -37,33 +93,11 @@ while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
;;
esac
done
ping_url="https://api.rosette.com/rest/v1"

# strip the trailing slash off of the alt_url if necessary
if [ ! -z "${ALT_URL}" ]; then
case ${ALT_URL} in
*/) ALT_URL=${ALT_URL::-1}
echo "Slash detected"
;;
esac
ping_url=${ALT_URL}
fi
cleanURL

#Checks for valid url
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
if [ "${match}" = "" ]; then
echo -e "\n${ping_url} server not responding\n"
exit 1
fi
validateURL

#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}

#Copy the mounted content in /source to current WORKDIR
cp -r -n /source/* .
Expand All @@ -75,15 +109,11 @@ if [ ! -z ${API_KEY} ]; then
python /python-dev/setup.py install
cd /python-dev/examples
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
else
python ${FILENAME} --key ${API_KEY}
fi
runExample ${FILENAME}
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
else
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
for file in *.py; do
runExample ${file}
done
fi
else
HELP
Expand All @@ -109,3 +139,5 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
git commit -a -m "publish python apidocs ${VERSION}"
git push
fi

exit ${retcode}
101 changes: 67 additions & 34 deletions examples/docker/run_python.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

retcode=0
ping_url="https://api.rosette.com/rest/v1"

#------------------ Functions ----------------------------------------------------

#Gets called when the user doesn't provide any args
function HELP {
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
Expand All @@ -10,6 +15,59 @@ function HELP {
exit 1
}

#Checks if Rosette API key is valid
function checkAPI() {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}

function cleanURL() {
# strip the trailing slash off of the alt_url if necessary
if [ ! -z "${ALT_URL}" ]; then
case ${ALT_URL} in
*/) ALT_URL=${ALT_URL::-1}
echo "Slash detected"
;;
esac
ping_url=${ALT_URL}
fi
}

function validateURL() {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" -H "user_key: ${API_KEY}" | grep -o "Rosette API")
if [ "${match}" = "" ]; then
echo -e "\n${ping_url} server not responding\n"
exit 1
fi
}

function runExample() {
echo -e "\n---------- ${1} start -------------"
result=""
if [ -z ${ALT_URL} ]; then
result="$(python ${1} --key ${API_KEY} 2>&1 )"
else
result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )"
fi
echo "${result}"
echo -e "\n---------- ${1} end -------------"
if [[ "${result}" == *"Exception"* ]]; then
echo "Exception found"
retcode=1
elif [[ "$result" == *"processingFailure"* ]]; then
retcode=1
elif [[ "$result" == *"AttributeError"* ]]; then
retcode=1
elif [[ "$result" == *"ImportError"* ]]; then
retcode=1
fi
}

#------------------ Functions End ------------------------------------------------

#Gets API_KEY, FILENAME and ALT_URL if present
while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
case "${arg}" in
Expand All @@ -27,33 +85,10 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
;;
esac
done
ping_url="https://api.rosette.com/rest/v1"

# strip the trailing slash off of the alt_url if necessary
if [ ! -z "${ALT_URL}" ]; then
case ${ALT_URL} in
*/) ALT_URL=${ALT_URL::-1}
echo "Slash detected"
;;
esac
ping_url=${ALT_URL}
fi

#Checks for valid url
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
if [ "${match}" = "" ]; then
echo -e "\n${ping_url} server not responding\n"
exit 1
fi
cleanURL

#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
if [ ! -z $match ]; then
echo -e "\nInvalid Rosette API Key"
exit 1
fi
}
validateURL

#Copy the examples from the mounted content in /source to current WORKDIR
cp /source/examples/*.* .
Expand All @@ -62,16 +97,14 @@ cp /source/examples/*.* .
if [ ! -z ${API_KEY} ]; then
checkAPI
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
else
python ${FILENAME} --key ${API_KEY}
fi
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
runExample ${FILENAME}
else
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
fi
for file in *.py; do
runExample ${file}
done
fi
else
HELP
fi

exit ${retcode}
2 changes: 1 addition & 1 deletion rosette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
limitations under the License.
"""

__version__ = '0.8.0'
__version__ = '1.0'
2 changes: 1 addition & 1 deletion rosette/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from datetime import datetime
import requests

_BINDING_VERSION = "0.10"
_BINDING_VERSION = "1.0"
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
N_RETRIES = 3
HTTP_CONNECTION = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read(*filenames, **kwargs):
buf.append(f.read())
return sep.join(buf)

long_description = read('README.md', 'CHANGES.txt')
long_description = read('README.md')

setup(name=NAME,
author=AUTHOR,
Expand Down

0 comments on commit a6368c5

Please sign in to comment.