-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathvisualpy
More file actions
325 lines (287 loc) · 7.49 KB
/
visualpy
File metadata and controls
325 lines (287 loc) · 7.49 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#============================================================================
#!/bin/sh
#============================================================================
# Filename : visualpy
# function : control visualpython for Mac/Linux
# Creator : BlackLogic - LJ
# version : 2.1
# License :
# Date : 2020 07.27
# Mdate : 2020 12.29
#============================================================================
v_path1=`pip show visualpython | grep Location | awk -F': ' '{print $2}'`
v_prod='visualpython'
v_str1='jupyter nbextension'
v_str2='visualpython/src/main'
v_unst='pip uninstall '${v_prod}
v_upgr='pip install '${v_prod}' --upgrade'
#v_srch='pip search '${v_prod}
v_str3='pip list -o '
v_str4='pip show '${v_prod}
#v_list=`${v_str3} | grep -i ${v_prod}`
v_curt=`${v_str4} | grep 'Version' | cut -d ' ' -f 2`
v_option=$1
#echo ${v_list}
#exit
# main function
f_main() {
case ${v_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
}
f_check_conda() {
if hash conda-env 2>/dev/null; then
echo 1
else
echo 0
fi
}
f_setting_path() {
v_return=$( f_check_conda )
# 0 == not a conda env
# 1 == conda env
if [ $v_return -eq 0 ]; then
v_path2=`jupyter --data-dir`/nbextensions
else
v_path2=`conda-env list | grep "*" | awk '{print $NF}'`/share/jupyter/nbextensions/
fi
echo ${v_path2}
}
# install visualpython function
f_install() {
v_return=$( f_check_extension )
# 1 == extension not active
# 2 == visualpython not exists
# 3 == visualpython exists
mkdir -p ${v_path2}${v_prod}
if [ ${v_return} -eq 1 ]; then
f_prt_extensiondir
elif [ ${v_return} -eq 3 ]; then
# overwrite
f_prt_visualpythondir
f_disable
f_remove_files
f_copy_files
f_enable
else
f_copy_files
f_enable
fi
}
# uninstall visualpython function
f_uninstall() {
v_return=$( f_check_extension )
# 1 == extension not active
# 2 == visualpython not exists
# 3 == visualpython exists
if [ ${v_return} -eq 3 ]; then
f_prt_line1
f_disable
f_prt_line2
f_remove_files
f_prt_line2
${v_unst}
f_prt_line1
elif [ ${v_return} -eq 2 ]; then
f_prt_line2
${v_unst}
f_prt_line2
fi
}
# upgrade visualpython package
f_upgrade() {
# v_return=$( f_version_cmp )
# 0 == upgrade
# 1 == pass
# setting current version
# v_curt=`${v_str4} | grep 'Version' | cut -d ' ' -f 2`
f_prt_line1
echo "running upgrade"
f_prt_line2
${v_upgr}
# setting last version
v_last=`${v_str4} | grep 'Version' | cut -d ' ' -f 2`
if [ ${v_curt} = ${v_last} ]; then
f_prt_line2
echo "Already installed last Visual Python version."
f_prt_line2
echo "Installed version : "${v_curt}
echo "Last Release version : "${v_last}
f_prt_line1
else
f_prt_line2
f_disable
f_copy_files
f_enable
f_prt_line1
fi
}
# enable visualpython function
f_enable() {
v_return=$( f_check_extension )
if [ ${v_return} -eq 3 ]; then
${v_str1} enable ${v_str2}
fi
}
# disable visualpython function
f_disable() {
v_return=$( f_check_extension )
if [ ${v_return} -eq 3 ]; then
${v_str1} disable ${v_str2}
fi
}
# check visualpython files function
f_check_extension() {
if [ ! -e ${v_path2} ]; then
echo 1
elif [ ! -e ${v_path2}/${v_prod} ]; then
echo 2
else
echo 3
fi
}
# current visualpython version, last release version
f_version() {
v_result=${v_list}
f_prt_line1
echo "Check visualpython version"
f_prt_line2
if [ 0 -eq ${#v_result} ]; then
echo "Already installed last version"
f_prt_line2
v_ver=`${v_str4} | grep Version | awk '{print $2}'`
echo "Installed version : "${v_ver}
echo "Last Release version : "${v_ver}
else
v_idx=1
for v_info in ${v_result}
do
if [ ${v_idx} -eq 2 ]; then
echo "Installed version : "${v_info}
elif [ ${v_idx} -eq 3 ]; then
echo "Last Release version : "${v_info}
fi
v_idx=`expr $v_idx + 1`
done
fi
f_prt_line1
}
## version compare
f_version_cmp() {
v_result=${v_list}
if [ 0 -ne ${#v_result} ]; then
## upgrade
echo 0
else
echo 1
fi
}
# copy visualpython function
f_copy_files() {
f_prt_line1
echo "Copy visualpyhthon extension files ..."
f_prt_line2
echo "Source Dir : " ${v_path1}/${v_prod}
echo "Target Dir : " ${v_path2}${v_prod}
f_prt_line1
cp -Rp ${v_path1}/${v_prod} ${v_path2}/.
}
f_prt_line1() {
echo "============================================================================================"
}
f_prt_line2() {
echo "--------------------------------------------------------------------------------------------"
}
# remove visualpython function
f_remove_files() {
f_prt_line1
if [ -e ${v_path2}/${v_prod} ]; then
echo "Remove Visual Python Directories."
echo "Target Dir : " ${v_path2}
\rm -rf ${v_path2}/${v_prod}
else
echo "not exists visualpython dir"
fi
}
# overwrite visualpython function
f_overwrite() {
v_return=$( f_check_extension )
# 1 == extension not active
# 2 == visualpython not exists
# 3 == visualpython exists
echo ${v_return}
echo ${v_path2}
if [ ${v_return} -eq 1 ]; then
f_prt_extensiondir
elif [ ${v_return} -eq 3 ]; then
f_disable
f_remove_files
f_copy_files
f_enable
else
f_install
fi
}
# help options
f_help() {
echo ""
echo "usage: visualpy [option]"
echo ""
echo "optional arguments:"
echo " help, -h, -H, show this help message and exit"
echo " enable, -E, -e enable Visual Python"
echo " disable, -D, -d disable Visual Python"
echo " install, -i, -I install Visual Python extensions"
echo " uninstall, -un, -UN uninstall Visual Python packages"
echo " upgrade, -up, -UP upgrade Visual Python Package"
echo " version, -V, -v show Visual Python release & current version"
echo ""
}
# print extension not installed
f_prt_extensiondir() {
echo "Nbextension not activated"
echo "Plz install nbextension"
f_prt_line1
echo "for conda env"
echo "conda install -c conda-forge jupyter_contrib_nbextensions"
echo "jupyter contrib nbextension install --user"
f_prt_line2
echo "for pip"
echo "pip install -e jupyter_contrib_nbextensions"
echo "jupyter contrib nbextension install --user"
f_prt_line1
}
# print visualpython exists
f_prt_visualpythondir() {
f_prt_line1
echo "Already exists Visual Python."
f_prt_line1
}
# print other messages
f_prt_other_massages() {
echo "invalid option : " ${v_option}
echo "Please check Visual Python option cmd"
echo "cmd : visualpy -h "
}
# execute main
v_path2=$( f_setting_path )
f_main
exit
#============================================================================
#End of File
#============================================================================