-
Notifications
You must be signed in to change notification settings - Fork 7
/
DeviceBuilder_NodeIotivityServer.sh
161 lines (138 loc) · 6.17 KB
/
DeviceBuilder_NodeIotivityServer.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#############################
#
# copyright 2016 Open Interconnect Consortium, Inc. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE OPEN INTERCONNECT CONSORTIUM, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR
# WARRANTIES OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE OPEN INTERCONNECT CONSORTIUM, INC. OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#############################
#
# usage
# sh DeviceBuilder_NodeIotivityServer.sh <devicbuilder input file> <output directory>
# <devicbuilder input file> : see https://github.com/openconnectivityfoundation/DeviceBuilder/tree/master/test/input_define_device for examples
# <output directory> will be created
#
# This script generates:
# - introspection file in json and cbor
# - swagger file for code generation
# - node.js code
#
# things one needs:
# - git
# - python3 installation
# - wb-swagger https://github.com/WAvdBeek/wb-swagger-node globally installed
#
# example command:
#$ sh DeviceBuilder_NodeIotivityServer.sh ./test/input_define_device/input-lightdevice.json ../out-device/light
#
# This will create an output folder 1 level higher than the github repo and should have the generated files in the light sub folder.
# This will have :
# - Input-lightdevice.json (e.g. the input file…)
# - out_codegeneration_merged.swagger.json : the input file for swagger2x
# - out_introspection_merged.swagger.json : the introspection file in json
# - out_introspection_merged.swagger.json.cbor : the introspection file in cbor
# - code (folder)
# - readme.txt
# - Server.js the node.js server that should work with IOTivity Node.
PYTHON_EXE=C:\\python35-32\\python3.exe
DeviceBuilder=./src/DeviceBuilder.py
SWAG2CBOR=./src/swag2cbor.py
SWAGGER2XDIR=../swagger2x
SWAGGER2X=$SWAGGER2XDIR/src/swagger2x.py
INPUTFILE=$1
OUTPUTDIR=$2
MODELS_DIR=../IoTDataModels
CORE_DIR=../core
echo "input file: " $INPUTFILE
echo "output folder:" $OUTPUTDIR
PIP_INSTALLED=`which pip3`
if stringContain "not found" $PIP_INSTALLED;then
echo "== installing pip3"
sudo apt-get -y install python3-pip
else
echo "pip3 installed: $PIP_INSTALLED"
fi
#
# multiple checks on what is already there.
#
`$PYTHON_EXE -c "import sys, pkgutil; sys.exit(0 if pkgutil.find_loader('cbor') else 1)"`
PyPACKAGE_INSTALLED=$?
if [ $PyPACKAGE_INSTALLED -eq 1 ];then
echo "== installing python dependencies" $PyPACKAGE_INSTALLED
$PIP3 install -U -r requirements-setuptools.txt
$PIP3 install -U -r requirements.txt
else
echo "python package cbor installed, assuming all other packages are installed too"
echo "if not run on the commandline: $PIP3 install -U -r requirements.txt"
fi
`$PYTHON_EXE -c "import sys, pkgutil; sys.exit(0 if pkgutil.find_loader('Jinja2') else 1)"`
PyPACKAGE_INSTALLED=$?
if [ $PyPACKAGE_INSTALLED -eq 1 ];then
echo "== installing python dependencies" $PyPACKAGE_INSTALLED
$PIP3 install -U -r requirements-setuptools.txt
$PIP3 install -U -r requirements.txt
else
echo "python package Jinja2 installed, assuming all other packages are installed too"
echo "if not run on the commandline: $PIP3 install -U -r requirements.txt"
fi
`$PYTHON_EXE -c "import sys, pkgutil; sys.exit(0 if pkgutil.find_loader('deepdiff') else 1)"`
PyPACKAGE_INSTALLED=$?
if [ $PyPACKAGE_INSTALLED -eq 1 ];then
echo "== installing python dependencies" $PyPACKAGE_INSTALLED
$PIP3 install -U -r requirements-setuptools.txt
$PIP3 install -U -r requirements.txt
else
echo "python package deepdiff installed, assuming all other packages are installed too"
echo "if not run on the commandline: $PIP3 install -U -r requirements.txt"
fi
if [ ! -f $MODELS_DIR/README.md ]
then
pushd `pwd`
cd ..
git clone https://github.com/openconnectivityfoundation/IoTDataModels.git --branch master
popd
fi
if [ ! -f $CORE_DIR/README.md ]
then
pushd `pwd`
cd ..
git clone https://github.com/openconnectivityfoundation/core.git --branch master
popd
fi
if [ ! -f $MODELS_DIR/oic.wk.res.swagger.json ]
then
echo "copying $CORE_DIR/swagger2.0/*.swagger.json $MODELS_DIR/*"
cp $CORE_DIR/swagger2.0/*.swagger.json $MODELS_DIR
fi
if [ ! -f $SWAGGER2X ]
then
pushd `pwd`
cd ..
git clone https://github.com/openconnectivityfoundation/swagger2x.git --branch master
popd
fi
echo "creating $OUTPUTDIR"
mkdir -p $OUTPUTDIR
cp $INPUTFILE $OUTPUTDIR
$PYTHON_EXE ./src/install.py
$PYTHON_EXE $DeviceBuilder -input $INPUTFILE -resource_dir $MODELS_DIR -out $OUTPUTDIR/out
wb-swagger validate $OUTPUTDIR/out_introspection_merged.swagger.json
$PYTHON_EXE $SWAG2CBOR -file $OUTPUTDIR/out_introspection_merged.swagger.json
#-template_dir ../src/templates -template NodeIotivityServer -swagger ../test/in/test_swagger_1/test_swagger_1.swagger.json -out_dir $OUTPUT_DIR/$TEST_CAS
mkdir -p $OUTPUTDIR/code
$PYTHON_EXE $SWAGGER2XDIR/src/install.py
$PYTHON_EXE $SWAGGER2X -template_dir $SWAGGER2XDIR/src/templates -template NodeIotivityServer -swagger $OUTPUTDIR/out_codegeneration_merged.swagger.json -out_dir $OUTPUTDIR/code