Skip to content

Commit a6368c5

Browse files
committed
Merge pull request #36 from cp2boston/develop
RCB-357 Updated script to detect exceptions
2 parents 9da71bf + 3720a2c commit a6368c5

File tree

7 files changed

+136
-75
lines changed

7 files changed

+136
-75
lines changed

CHANGES.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include README.md CHANGES.txt LICENSE.txt
1+
include README.md LICENSE.txt
22
exclude MANIFEST.in

docker/run_python.sh

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/bash
22

3+
retcode=0
4+
ping_url="https://api.rosette.com/rest/v1"
5+
6+
#------------------ Functions ----------------------------------------------------
37
#Gets called when the user doesn't provide any args
48
function HELP {
5-
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
9+
echo -e "\nusage: --key API_KEY [--FILENAME filename] [--url ALT_URL]"
610
echo " API_KEY - Rosette API key (required)"
711
echo " FILENAME - Python source file (optional)"
812
echo " ALT_URL - Alternate service URL (optional)"
@@ -12,6 +16,58 @@ function HELP {
1216
exit 1
1317
}
1418

19+
#Checks if Rosette API key is valid
20+
function checkAPI {
21+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
22+
if [ ! -z $match ]; then
23+
echo -e "\nInvalid Rosette API Key"
24+
exit 1
25+
fi
26+
}
27+
28+
function cleanURL() {
29+
# strip the trailing slash off of the alt_url if necessary
30+
if [ ! -z "${ALT_URL}" ]; then
31+
case ${ALT_URL} in
32+
*/) ALT_URL=${ALT_URL::-1}
33+
echo "Slash detected"
34+
;;
35+
esac
36+
ping_url=${ALT_URL}
37+
fi
38+
}
39+
40+
function validateURL() {
41+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "Rosette API")
42+
if [ "${match}" = "" ]; then
43+
echo -e "\n${ping_url} server not responding\n"
44+
exit 1
45+
fi
46+
}
47+
48+
function runExample() {
49+
echo -e "\n---------- ${1} start -------------"
50+
result=""
51+
if [ -z ${ALT_URL} ]; then
52+
result="$(python ${1} --key ${API_KEY} 2>&1 )"
53+
else
54+
result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )"
55+
fi
56+
echo "${result}"
57+
echo -e "\n---------- ${1} end -------------"
58+
if [[ "${result}" == *"Exception"* ]]; then
59+
echo "Exception found"
60+
retcode=1
61+
elif [[ "$result" == *"processingFailure"* ]]; then
62+
retcode=1
63+
elif [[ "$result" == *"AttributeError"* ]]; then
64+
retcode=1
65+
elif [[ "$result" == *"ImportError"* ]]; then
66+
retcode=1
67+
fi
68+
}
69+
#------------------ Functions End ------------------------------------------------
70+
1571
#Gets API_KEY, FILENAME and ALT_URL if present
1672
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
1773
case "${arg}" in
@@ -37,33 +93,11 @@ while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
3793
;;
3894
esac
3995
done
40-
ping_url="https://api.rosette.com/rest/v1"
4196

42-
# strip the trailing slash off of the alt_url if necessary
43-
if [ ! -z "${ALT_URL}" ]; then
44-
case ${ALT_URL} in
45-
*/) ALT_URL=${ALT_URL::-1}
46-
echo "Slash detected"
47-
;;
48-
esac
49-
ping_url=${ALT_URL}
50-
fi
97+
cleanURL
5198

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

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

68102
#Copy the mounted content in /source to current WORKDIR
69103
cp -r -n /source/* .
@@ -75,15 +109,11 @@ if [ ! -z ${API_KEY} ]; then
75109
python /python-dev/setup.py install
76110
cd /python-dev/examples
77111
if [ ! -z ${FILENAME} ]; then
78-
if [ ! -z ${ALT_URL} ]; then
79-
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
80-
else
81-
python ${FILENAME} --key ${API_KEY}
82-
fi
112+
runExample ${FILENAME}
83113
elif [ ! -z ${ALT_URL} ]; then
84-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
85-
else
86-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
114+
for file in *.py; do
115+
runExample ${file}
116+
done
87117
fi
88118
else
89119
HELP
@@ -109,3 +139,5 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
109139
git commit -a -m "publish python apidocs ${VERSION}"
110140
git push
111141
fi
142+
143+
exit ${retcode}

examples/docker/run_python.sh

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
retcode=0
4+
ping_url="https://api.rosette.com/rest/v1"
5+
6+
#------------------ Functions ----------------------------------------------------
7+
38
#Gets called when the user doesn't provide any args
49
function HELP {
510
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
@@ -10,6 +15,59 @@ function HELP {
1015
exit 1
1116
}
1217

18+
#Checks if Rosette API key is valid
19+
function checkAPI() {
20+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
21+
if [ ! -z $match ]; then
22+
echo -e "\nInvalid Rosette API Key"
23+
exit 1
24+
fi
25+
}
26+
27+
function cleanURL() {
28+
# strip the trailing slash off of the alt_url if necessary
29+
if [ ! -z "${ALT_URL}" ]; then
30+
case ${ALT_URL} in
31+
*/) ALT_URL=${ALT_URL::-1}
32+
echo "Slash detected"
33+
;;
34+
esac
35+
ping_url=${ALT_URL}
36+
fi
37+
}
38+
39+
function validateURL() {
40+
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" -H "user_key: ${API_KEY}" | grep -o "Rosette API")
41+
if [ "${match}" = "" ]; then
42+
echo -e "\n${ping_url} server not responding\n"
43+
exit 1
44+
fi
45+
}
46+
47+
function runExample() {
48+
echo -e "\n---------- ${1} start -------------"
49+
result=""
50+
if [ -z ${ALT_URL} ]; then
51+
result="$(python ${1} --key ${API_KEY} 2>&1 )"
52+
else
53+
result="$(python ${1} --key ${API_KEY} --url ${ALT_URL} 2>&1 )"
54+
fi
55+
echo "${result}"
56+
echo -e "\n---------- ${1} end -------------"
57+
if [[ "${result}" == *"Exception"* ]]; then
58+
echo "Exception found"
59+
retcode=1
60+
elif [[ "$result" == *"processingFailure"* ]]; then
61+
retcode=1
62+
elif [[ "$result" == *"AttributeError"* ]]; then
63+
retcode=1
64+
elif [[ "$result" == *"ImportError"* ]]; then
65+
retcode=1
66+
fi
67+
}
68+
69+
#------------------ Functions End ------------------------------------------------
70+
1371
#Gets API_KEY, FILENAME and ALT_URL if present
1472
while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
1573
case "${arg}" in
@@ -27,33 +85,10 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
2785
;;
2886
esac
2987
done
30-
ping_url="https://api.rosette.com/rest/v1"
31-
32-
# strip the trailing slash off of the alt_url if necessary
33-
if [ ! -z "${ALT_URL}" ]; then
34-
case ${ALT_URL} in
35-
*/) ALT_URL=${ALT_URL::-1}
36-
echo "Slash detected"
37-
;;
38-
esac
39-
ping_url=${ALT_URL}
40-
fi
4188

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

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

5893
#Copy the examples from the mounted content in /source to current WORKDIR
5994
cp /source/examples/*.* .
@@ -62,16 +97,14 @@ cp /source/examples/*.* .
6297
if [ ! -z ${API_KEY} ]; then
6398
checkAPI
6499
if [ ! -z ${FILENAME} ]; then
65-
if [ ! -z ${ALT_URL} ]; then
66-
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
67-
else
68-
python ${FILENAME} --key ${API_KEY}
69-
fi
70-
elif [ ! -z ${ALT_URL} ]; then
71-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
100+
runExample ${FILENAME}
72101
else
73-
find -maxdepth 1 -name '*.py' -print -exec python {} --key ${API_KEY} \;
74-
fi
102+
for file in *.py; do
103+
runExample ${file}
104+
done
105+
fi
75106
else
76107
HELP
77108
fi
109+
110+
exit ${retcode}

rosette/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
limitations under the License.
1717
"""
1818

19-
__version__ = '0.8.0'
19+
__version__ = '1.0'

rosette/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from datetime import datetime
3030
import requests
3131

32-
_BINDING_VERSION = "0.10"
32+
_BINDING_VERSION = "1.0"
3333
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
3434
N_RETRIES = 3
3535
HTTP_CONNECTION = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def read(*filenames, **kwargs):
2323
buf.append(f.read())
2424
return sep.join(buf)
2525

26-
long_description = read('README.md', 'CHANGES.txt')
26+
long_description = read('README.md')
2727

2828
setup(name=NAME,
2929
author=AUTHOR,

0 commit comments

Comments
 (0)