-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathvisualpy
More file actions
311 lines (276 loc) · 9.43 KB
/
visualpy
File metadata and controls
311 lines (276 loc) · 9.43 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#
# Project Name : Visual Python
# Description : GUI-based Python code generator
# File Name : visualpy
# Author : Black Logic - LJ
# Note : Control Visual Python for Mac/Linux
# License : GPLv3 (GNU General Public License v3.0)
# Date : 2021. 08. 14
# Change Date :
#
#=============================================================================
# Check Arguments
# - set VP_OPTION & PIP_T
#=============================================================================
if [ $# -eq 1 ]; then
VP_OPTION=$1
elif [ $# -eq 2 ]; then
ARG1=$(echo $1 | cut -c1-2)
if [ ${ARG1} = "--" ]; then
VP_OPTION=$2
PIP_T=$(echo $1 | cut -c3-)
else
VP_OPTION=$1
PIP_T=$(echo $2 | cut -c3-)
fi
else
VP_OPTION=''
fi
#=============================================================================
# Set variable
#=============================================================================
PIP=pip
which ${PIP_T} > /dev/null 2>&1 && PIP=${PIP_T}
JP_NB='jupyter nbextension'
VP_NAME='visualpython'
VP_BIND='visualpython/visualpython'
PIP_UNINST=${PIP}' uninstall '${VP_NAME}
PIP_UPGRAD=${PIP}' install '${VP_NAME}' --upgrade'
#=============================================================================
# main function
#=============================================================================
f_main() {
echo "Package install command: ${PIP}"
case ${VP_OPTION} in
enable | -E | -e | \
disable | -D | -d | \
install | -I | -i | \
uninstall | -UN | -un | \
upgrade | -UP | -up)
PATH_SRC=`f_get_string_pipshow Location`
PATH_DST=`f_get_extension_path` ;;
esac
case ${VP_OPTION} in
enable | -E | -e) f_enable ;;
disable | -D | -d) f_disable ;;
install | -I | -i) f_install ;;
uninstall | -UN | -un) f_uninstall ;;
upgrade | -UP | -up) f_upgrade ;;
version | -V | -v) f_version ;;
help | -H | -h) f_help ;;
*) f_help;;
esac
}
#=============================================================================
# Install Visual Python
#=============================================================================
f_install() {
mkdir -p ${PATH_DST}
RES=`f_check_extension`
# 1 = Jupyter Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists
if [ ${RES} -eq 1 ]; then
f_print_not_extension
elif [ ${RES} -eq 2 ]; then
f_copy_files
f_enable
elif [ ${RES} -eq 3 ]; then
# overwrite
f_print_line1
echo "Already exists Visual Python."
f_print_line1
f_disable
f_remove_files
f_copy_files
f_enable
fi
}
#=============================================================================
# Uninstall Visual Python
#=============================================================================
f_uninstall() {
RES=`f_check_extension`
# 1 = Jupyter Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists
if [ ${RES} -eq 2 ]; then
f_print_line2
${PIP_UNINST}
f_print_line2
elif [ ${RES} -eq 3 ]; then
f_print_line1
f_disable
f_print_line2
f_remove_files
f_print_line2
${PIP_UNINST}
f_print_line1
fi
}
#=============================================================================
# Upgrade Visual Python
#=============================================================================
f_upgrade() {
f_print_line1
echo "Running upgrade Visual Python"
f_print_line2
# Get Visual Python version
VP_VERSION=`f_get_string_pipshow Version`
${PIP_UPGRAD}
# Get Visual Python new version
VP_VERSION_NEW=`f_get_string_pipshow Version`
if [ ${VP_VERSION} = ${VP_VERSION_NEW} ]; then
f_print_line2
echo "Already installed last Visual Python version."
f_print_line2
echo "Installed version : "${VP_VERSION}
echo "Last Release version : "${VP_VERSION_NEW}
f_print_line1
else
f_print_line2
f_disable
f_remove_files
f_copy_files
f_enable
f_print_line1
fi
}
#=============================================================================
# Enable Visual Python
#=============================================================================
f_enable() {
RES=`f_check_extension`
if [ ${RES} -eq 3 ]; then
${JP_NB} enable ${VP_BIND}
fi
}
#=============================================================================
# Disable Visual Python
#=============================================================================
f_disable() {
RES=`f_check_extension`
if [ ${RES} -eq 3 ]; then
${JP_NB} disable ${VP_BIND}
fi
}
#=============================================================================
# Visual Python version
#=============================================================================
f_version() {
VP_VERSION=`f_get_string_pipshow Version`
echo "Visual Python "${VP_VERSION}
}
#=============================================================================
# Help messages
#=============================================================================
f_help() {
echo ""
echo "usage: visualpy [option] [--pip3]"
echo ""
echo "optional arguments:"
echo " -h, help show this help message and exit"
echo " -e, enable enable Visual Python"
echo " -d, disable disable Visual Python"
echo " -i, install install Visual Python extensions"
echo " -ui, uninstall uninstall Visual Python packages"
echo " -up, upgrade upgrade Visual Python Package"
echo " -v, version show Visual version and exit"
echo ""
echo " --pip3 use pip3 [default: pip]"
echo ""
}
#=============================================================================
# Copy Visual Python files
#=============================================================================
f_copy_files() {
f_print_line1
echo "Copy visualpyhthon extension files ..."
f_print_line2
echo "Source Dir : " ${PATH_SRC}/${VP_NAME}
echo "Target Dir : " ${PATH_DST}/${VP_NAME}
f_print_line1
cp -Rp ${PATH_SRC}/${VP_NAME} ${PATH_DST}/.
}
#=============================================================================
# Remove Visual Python files
#=============================================================================
f_remove_files() {
f_print_line1
if [ -e ${PATH_DST}/${VP_NAME} ]; then
echo "Remove Visual Python Directories."
echo "Target Dir : " ${PATH_DST}
\rm -rf ${PATH_DST}/${VP_NAME}
else
echo "not exists visualpython dir"
fi
}
#=============================================================================
# Check Visual Python files
# 1 = Jupyter Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists
#=============================================================================
f_check_extension() {
if [ ! -e ${PATH_DST} ]; then
echo 1
elif [ ! -e ${PATH_DST}/${VP_NAME} ]; then
echo 2
else
echo 3
fi
}
#=============================================================================
# Get string(Version or Location) from pip show
# $1 = Version or Location
#=============================================================================
f_get_string_pipshow() {
RESULT="EMPTY"
if [ $# -ge 1 ]; then
RESULT=`${PIP} show ${VP_NAME} | grep $1 | awk -F':' '{print $2}' | tr -d ' '`
fi
echo ${RESULT}
}
#=============================================================================
# Get string(Jupyter nbextension path) from conda-env or jupyter
#=============================================================================
f_get_extension_path() {
RESULT="EMPTY"
if which conda-env > /dev/null 2>&1; then
RESULT=`conda-env list | grep "*" | awk -F'*' '{print $2}'|tr -d ' '`/share/jupyter/nbextensions
else
RESULT=`jupyter --data-dir`/nbextensions
fi
echo ${RESULT}
}
#=============================================================================
# Print extension is not installed
#=============================================================================
f_print_not_extension() {
echo "Jupyter nbextension is not activated"
echo "Please install Jupyter nbextension"
f_print_line1
echo "for conda env"
echo "conda install -c conda-forge jupyter_contrib_nbextensions"
echo "jupyter contrib nbextension install --user"
f_print_line2
echo "for pip"
echo ${PIP}" install -e jupyter_contrib_nbextensions"
echo "jupyter contrib nbextension install --user"
f_print_line1
}
#=============================================================================
# Print line
#=============================================================================
f_print_line1() {
echo "============================================================================================"
}
f_print_line2() {
echo "--------------------------------------------------------------------------------------------"
}
#=============================================================================
# Execute main function
#=============================================================================
f_main
exit 0
# End of file