forked from rosette-api/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_python.sh
More file actions
59 lines (54 loc) · 1.58 KB
/
run_python.sh
File metadata and controls
59 lines (54 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#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 " API_KEY - Rosette API key (required)"
echo " FILENAME - Python source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
echo "Compiles and runs the source file(s) using the published rosette-api"
exit 1
}
#Gets API_KEY, FILENAME and ALT_URL if present
while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
case "${arg}" in
API_KEY)
API_KEY=${OPTARG}
usage
;;
ALT_URL)
ALT_URL=${OPTARG}
usage
;;
FILENAME)
FILENAME=${OPTARG}
usage
;;
esac
done
#Checks if Rosette API key is valid
function checkAPI {
match=$(curl "https://api.rosette.com/rest/v1/ping" -H "user_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 /source/*.* .
#Run the examples
if [ ! -z ${API_KEY} ]; then
checkAPI
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
tox -- ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
else
tox -- ${FILENAME} --key ${API_KEY}
fi
elif [ ! -z ${ALT_URL} ]; then
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} --url ${ALT_URL} \;
else
find -maxdepth 1 -name '*.py' -print -exec tox -- {} --key ${API_KEY} \;
fi
else
HELP
fi