-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoPorisRuby.sh
executable file
·116 lines (96 loc) · 4.1 KB
/
doPorisRuby.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
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied"
exit 1;
fi
FILE=models/$1.ods
if test -f "$FILE"; then
echo "Input $FILE exists, continuing"
else
echo "Input $FILE does not exist, aborting"
exit 1;
fi
if [ -z ${PORIS_SAFETY_OVERRIDE+x} ]; then
echo "PORIS_SAFETY_OVERRIDE is not set, checking repo is clean";
if [ -z "$(git status --porcelain)" ]; then
echo "Welcome to doPorisRuby.sh"
else
# Uncommitted changes
echo "ERROR: YOUR REPOSITORY IS NOT CLEAN"
echo "As executing this process can overwrite manual code"
echo "you are encouraged to have commited/reverted any change"
echo "in the repo so in case of loosing something you will have"
echo "the opportunity to recover it (in case you commited it)"
echo "or you will be the only responsible of having lost it "
echo "(in case you reverted)."
exit 1;
fi
else
echo "PORIS_SAFETY_OVERRIDE is set, skip checking repo is clean";
echo "Welcome to doPorisRuby.sh"
fi
######### SAFETY AREA ############
########### USER CONFIGURATION AREA ##############
# Defining some environmental variables
# TODO: Convert them to arguments
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DEVBASE_PATH=`pwd`
########### INTERNAL VARIABLES CALCULATION AREA ##############
# Some "constants"
# The name of the device, get from the script first argument
DEVPATH=$1
DEVNAME=${DEVPATH##*/}
OUTPUT_BASE=${DEVPATH%"$DEVNAME"}
echo ${DEVPATH}
echo ${DEVNAME}
echo ${OUTPUT_BASE}
OUTPUT_PATH=${DEVBASE_PATH}'/output/rb/'${OUTPUT_BASE}
# The path for the C++ base folder for the devices
# This is the folder for the PORIS tools path.
# Normally set to PORIS_TOOLS_PYTHON_PATH=${DEVBASE_PYTHON_PATH}/PORIS, but if you
# change DEVBASE_RELATIVE_PATH you might want to separate the link
# between the two variables
PORIS_TOOLS_PATH=${SCRIPT_DIR}
PORIS_TOOLS_PYTHON_PATH=${SCRIPT_DIR}
echo "path"
echo ${PORIS_TOOLS_PATH}
echo ${PORIS_TOOLS_PYTHON_PATH}
# The path for the C++ base folder for the specific (user) custom code of the device
OUTPUT_PHYS_PATH=${OUTPUT_PATH}/${DEVNAME}_physical
########### WELCOME MESSAGE CALCULATION AREA ##############
echo "Welcome to Python code generator por PORIS models"
######### CLEANING AREA ###############
# We will clean the previous products
echo "Cleaning previous generated products"
rm -rf ${OUTPUT_PATH}/${DEVNAME}
######### CREATING FOLDERS AREA ###############
# Let's create the product directories
echo "Creating "${OUTPUT_PATH}/${DEVNAME}
mkdir -p ${OUTPUT_PATH}/${DEVNAME}
ln -s ../../rbPORIS/PORIS/PORIS.rb ${OUTPUT_PATH}/${DEVNAME}/PORIS.rb
######### If no USER CUSTOM CODE FOLDER ADDED, COPY THE TEMPLATE ONE #############
echo "Checking the existence of ${DEVBASE_PYTHON_PHYS_PATH}"
if [ -d "$OUTPUT_PHYS_PATH" ]; then
### Take action if $DEVBASE_PHYS_PATH exists ###
echo "${OUTPUT_PHYS_PATH} already present, nothing to do"
else
### Control will jump here if $DEVBASE_PYTHON_PHYS_PATH does NOT exists ###
echo "${OUTPUT_PHYS_PATH} not found. Copying template dir."
cp -r ${PORIS_TOOLS_PYTHON_PATH}'/PORIS/$S1_physical' ${OUTPUT_PHYS_PATH}
echo ${DEVNAME}
echo "Renaming"${OUTPUT_PHYS_PATH}'/$S1_physical.rb to '${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
mv ${OUTPUT_PHYS_PATH}'/$S1_physical.rb' ${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
sed -i "s/DEVICENAME/$DEVNAME/" ${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
sed -i "s/DEVICENAME/$DEVNAME/" ${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
sed -i "s/DEVICENAME/$DEVNAME/" ${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
sed -i "s/DEVICENAME/$DEVNAME/" ${OUTPUT_PHYS_PATH}/${DEVNAME}_physical.rb
ln -s ../${DEVNAME}/${DEVNAME}PORIS.rb ${OUTPUT_PHYS_PATH}/${DEVNAME}PORIS.rb
ln -s ../../rbPORIS/PORIS/PORIS.rb ${OUTPUT_PHYS_PATH}/PORIS.rb
fi
######### PARSING THE MODEL AND GENERATING THE PORIS PRODUCTS ###############
cd ${DEVBASE_PATH}
echo "Generating the PORIS device products from $1.ods"
echo ${PORIS_TOOLS_PYTHON_PATH}
python3 ${PORIS_TOOLS_PYTHON_PATH}/poris2ruby.py models models/$1.ods output || { echo 'poris2ruby.py failed' ; exit 1; }
echo "Fin!"