forked from nutanix/xi-iot-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·130 lines (106 loc) · 3.19 KB
/
setup.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash -xe
function install_python27_env() {
sudo yum install -y python27 python27-devel gcc
python2.7 --version
curl https://bootstrap.pypa.io/get-pip.py | sudo python2.7
pip2.7 -V
sudo pip2.7 install --upgrade pip
sudo pip2.7 install virtualenv
virtualenv -p python2.7 venv
}
function install_python3_env() {
sudo yum install -y python3 python3-devel gcc
python3 --version
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
pip3 -V
sudo pip3 install --upgrade pip
sudo pip3 install virtualenv3
virtualenv3 -p python3 venv
}
function activate_python_env() {
. ./venv/bin/activate
}
function deactivate_python_env() {
deactivate
}
function install_xi_iot_sdk_python2() {
pushd xiiot_api
python setup.py install
popd
python -c "import xiiot_api"
retval=$?
if [[ "$retval" -ne "0" ]] ; then
exit $retval
fi
}
function install_xi_iot_sdk_python3() {
pushd xiiot_api
python3 setup.py install
popd
python3 -c "import xiiot_api"
retval=$?
if [[ "$retval" -ne "0" ]] ; then
exit $retval
fi
}
function list_pip_installed_modules() {
pip freeze
pip3 freeze
}
function uninstall_xi_io_api() {
pip uninstall -y xi-iot-sdk==1.0.0
pip3 uninstall -y xi-iot-sdk==1.0.0
}
function fetch_public_api_swagger_json() {
wget https://iot.nutanix.com/xi_iot_api.json -O xi_iot_api.json
}
function generate_code_from_json() {
download_swagger_codegen_cli
#if mac
# brew install swagger-codegen
# swagger-codegen generate -i ./xi_iot_api.json \
# -l python \
# -o ./xiiot_api \
# -DpackageName=xiiot_api,projectName=xi_iot_sdk
java -jar swagger-codegen-cli.jar config-help -l python
java -jar swagger-codegen-cli.jar help generate
java -jar swagger-codegen-cli.jar generate -i ./xi_iot_api.json \
-l python \
-o ./xiiot_api \
-DpackageName=xiiot_api,projectName=xi_iot_sdk
}
# function install_java() {
# }
function download_swagger_codegen_cli() {
SWAGGER_CODEGEN_CLI_JAR_HTTP=http://central.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.8/swagger-codegen-cli-3.0.8.jar
SWAGGER_CODEGEN_CLI_JAR=swagger-codegen-cli.jar
if [[ ! -f ${SWAGGER_CODEGEN_CLI_JAR} ]] ; then
wget ${SWAGGER_CODEGEN_CLI_JAR_HTTP} -O ${SWAGGER_CODEGEN_CLI_JAR}
fi
}
python_ver=-1
while getopts ":h23db:" opt; do
case ${opt} in
2 ) # process option 2
echo "user python ver2"
python_ver=2
;;
3 ) # process option 3
echo "user python ver3"
python_ver=3
;;
* ) echo "Usage: $0 [-h|--help] [-2|-3]"; exit 1
;;
esac
done
if [[ "$python_ver" == "-1" ]]; then
echo "Usage: $0 [-h|--help] [-2|-3]"; exit 1
fi
rm -r xiiot_api || true
fetch_public_api_swagger_json
generate_code_from_json
if [[ "$python_ver" == "2" ]]; then
install_xi_iot_sdk_python2
elif [[ "$python_ver" == "3" ]]; then
install_xi_iot_sdk_python3
fi