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
48function HELP {
59 echo -e " \nusage: source_file.py --key API_KEY [--url ALT_URL]"
@@ -12,6 +16,54 @@ 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+ fi
64+ }
65+ # ------------------ Functions End ------------------------------------------------
66+
1567# Gets API_KEY, FILENAME and ALT_URL if present
1668while getopts " :API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
1769 case " ${arg} " in
@@ -37,33 +89,11 @@ while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
3789 ;;
3890 esac
3991done
40- ping_url=" https://api.rosette.com/rest/v1"
4192
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
93+ cleanURL
5194
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
95+ validateURL
5896
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- }
6797
6898# Copy the mounted content in /source to current WORKDIR
6999cp -r -n /source/* .
@@ -75,15 +105,11 @@ if [ ! -z ${API_KEY} ]; then
75105 python /python-dev/setup.py install
76106 cd /python-dev/examples
77107 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
108+ runExample ${FILENAME}
83109 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} \;
110+ for file in * .py; do
111+ runExample ${file}
112+ done
87113 fi
88114else
89115 HELP
@@ -109,3 +135,5 @@ if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
109135 git commit -a -m " publish python apidocs ${VERSION} "
110136 git push
111137fi
138+
139+ exit ${retcode}
0 commit comments