Skip to content

Commit f555527

Browse files
committed
#78 - 2nd modify visualpy, visualpy.bat: Add argument(ex: --pip3 )
1 parent 14cac62 commit f555527

2 files changed

Lines changed: 386 additions & 282 deletions

File tree

bin/visualpy

Lines changed: 90 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,9 @@
99
# Change Date :
1010
#
1111

12-
#=============================================================================
13-
# Set variable
14-
#=============================================================================
15-
PIP=pip
16-
JP_NB='jupyter nbextension'
17-
18-
VP_NAME='visualpython'
19-
VP_BIND='visualpython/src/main'
20-
21-
PIP_UNINST=${PIP}' uninstall '${VP_NAME}
22-
PIP_UPGRAD=${PIP}' install '${VP_NAME}' --upgrade'
23-
24-
VP_VERSION=`${PIP} show ${VP_NAME} | grep Version | awk -F':' '{print $2}' | tr -d ' '`
25-
PATH_SRC=`${PIP} show ${VP_NAME} | grep Location | awk -F':' '{print $2}' | tr -d ' '`
26-
27-
# Set PATH_DST: nbextensions
28-
if which conda-env > /dev/null 2>&1; then
29-
PATH_DST=`conda-env list | grep "*" | awk '{print $NF}'|tr -d ' '`/share/jupyter/nbextensions
30-
else
31-
PATH_DST=`jupyter --data-dir`/nbextensions
32-
fi
33-
3412
#=============================================================================
3513
# Check Arguments
14+
# - set VP_OPTION & PIP_T
3615
#=============================================================================
3716
if [ $# -eq 1 ]; then
3817
VP_OPTION=$1
@@ -49,49 +28,65 @@ else
4928
VP_OPTION=''
5029
fi
5130

52-
which ${PIP_T}> /dev/null 2>&1 && PIP=${PIP_T}
31+
#=============================================================================
32+
# Set variable
33+
#=============================================================================
34+
PIP=pip
35+
which ${PIP_T} > /dev/null 2>&1 && PIP=${PIP_T}
36+
37+
JP_NB='jupyter nbextension'
38+
39+
VP_NAME='visualpython'
40+
VP_BIND='visualpython/src/main'
41+
42+
PIP_UNINST=${PIP}' uninstall '${VP_NAME}
43+
PIP_UPGRAD=${PIP}' install '${VP_NAME}' --upgrade'
5344

5445
#=============================================================================
5546
# main function
5647
#=============================================================================
5748
f_main() {
49+
echo "Package install command: ${PIP}"
50+
5851
case ${VP_OPTION} in
59-
enable | -E | -e)
60-
f_enable ;;
61-
disable | -D | -d)
62-
f_disable ;;
63-
install | -I | -i)
64-
f_install ;;
65-
uninstall | -UN | -un)
66-
f_uninstall ;;
67-
upgrade | -UP | -up)
68-
f_upgrade ;;
69-
version | -V | -v)
70-
f_version ;;
71-
help | -H | -h )
72-
f_help ;;
73-
*)
74-
f_help;;
52+
enable | -E | -e | \
53+
disable | -D | -d | \
54+
install | -I | -i | \
55+
uninstall | -UN | -un | \
56+
upgrade | -UP | -up)
57+
PATH_SRC=`f_get_string_pipshow Location`
58+
PATH_DST=`f_get_extension_path` ;;
59+
esac
60+
61+
case ${VP_OPTION} in
62+
enable | -E | -e) f_enable ;;
63+
disable | -D | -d) f_disable ;;
64+
install | -I | -i) f_install ;;
65+
uninstall | -UN | -un) f_uninstall ;;
66+
upgrade | -UP | -up) f_upgrade ;;
67+
version | -V | -v) f_version ;;
68+
help | -H | -h) f_help ;;
69+
*) f_help;;
7570
esac
7671
}
7772

7873
#=============================================================================
7974
# Install Visual Python
8075
#=============================================================================
8176
f_install() {
82-
V_RES=$(f_check_extension)
77+
RES=`f_check_extension`
8378
# 1 = Jupyterr Extension is not actived
8479
# 2 = visualpython does not exist
8580
# 3 = visualpython exists
8681

8782
mkdir -p ${PATH_DST}/${VP_NAME}
8883

89-
if [ ${V_RES} -eq 1 ]; then
84+
if [ ${RES} -eq 1 ]; then
9085
f_print_not_extension
91-
elif [ ${V_RES} -eq 2 ]; then
86+
elif [ ${RES} -eq 2 ]; then
9287
f_copy_files
9388
f_enable
94-
elif [ ${V_RES} -eq 3 ]; then
89+
elif [ ${RES} -eq 3 ]; then
9590
# overwrite
9691
f_print_line1
9792
echo "Already exists Visual Python."
@@ -108,16 +103,16 @@ f_install() {
108103
# Uninstall Visual Python
109104
#=============================================================================
110105
f_uninstall() {
111-
V_RES=$( f_check_extension )
106+
RES=`f_check_extension`
112107
# 1 = Jupyterr Extension is not actived
113108
# 2 = visualpython does not exist
114109
# 3 = visualpython exists
115110

116-
if [ ${V_RES} -eq 2 ]; then
111+
if [ ${RES} -eq 2 ]; then
117112
f_print_line2
118113
${PIP_UNINST}
119114
f_print_line2
120-
elif [ ${V_RES} -eq 3 ]; then
115+
elif [ ${RES} -eq 3 ]; then
121116
f_print_line1
122117
f_disable
123118
f_print_line2
@@ -133,12 +128,16 @@ f_uninstall() {
133128
#=============================================================================
134129
f_upgrade() {
135130
f_print_line1
136-
echo "Running upgrade"
131+
echo "Running upgrade Visual Python"
137132
f_print_line2
133+
134+
# Get Visual Python version
135+
VP_VERSION=`f_get_string_pipshow Version`
136+
138137
${PIP_UPGRAD}
139138

140139
# Get Visual Python new version
141-
VP_VERSION_NEW=`${PIP} show ${VP_NAME} | grep Version | awk -F':' '{print $2}' | tr -d ' '`
140+
VP_VERSION_NEW=`f_get_string_pipshow Version`
142141

143142
if [ ${VP_VERSION} = ${VP_VERSION_NEW} ]; then
144143
f_print_line2
@@ -161,8 +160,8 @@ f_upgrade() {
161160
# Enable Visual Python
162161
#=============================================================================
163162
f_enable() {
164-
V_RES=$(f_check_extension)
165-
if [ ${V_RES} -eq 3 ]; then
163+
RES=`f_check_extension`
164+
if [ ${RES} -eq 3 ]; then
166165
${JP_NB} enable ${VP_BIND}
167166
fi
168167
}
@@ -171,8 +170,8 @@ f_enable() {
171170
# Disable Visual Python
172171
#=============================================================================
173172
f_disable() {
174-
V_RES=$(f_check_extension)
175-
if [ ${V_RES} -eq 3 ]; then
173+
RES=`f_check_extension`
174+
if [ ${RES} -eq 3 ]; then
176175
${JP_NB} disable ${VP_BIND}
177176
fi
178177
}
@@ -181,6 +180,8 @@ f_disable() {
181180
# Visual Python version
182181
#=============================================================================
183182
f_version() {
183+
VP_VERSION=`f_get_string_pipshow Version`
184+
184185
echo "Visual Python "${VP_VERSION}
185186
}
186187

@@ -189,18 +190,18 @@ f_version() {
189190
#=============================================================================
190191
f_help() {
191192
echo ""
192-
echo "usage: visualpy [option] | --pip3"
193+
echo "usage: visualpy [option] [--pip3]"
193194
echo ""
194195
echo "optional arguments:"
195-
echo " help, -h, -H, show this help message and exit"
196-
echo " enable, -E, -e enable Visual Python"
197-
echo " disable, -D, -d disable Visual Python"
198-
echo " install, -i, -I install Visual Python extensions"
199-
echo " uninstall, -un, -UN uninstall Visual Python packages"
200-
echo " upgrade, -up, -UP upgrade Visual Python Package"
201-
echo " version, -V, -v show Visual Python release & current version"
196+
echo " -h, help show this help message and exit"
197+
echo " -e, enable enable Visual Python"
198+
echo " -d, disable disable Visual Python"
199+
echo " -i, install install Visual Python extensions"
200+
echo " -ui, uninstall uninstall Visual Python packages"
201+
echo " -up, upgrade upgrade Visual Python Package"
202+
echo " -v, version show Visual version and exit"
202203
echo ""
203-
echo " --pip3 use pip3 [default: pip]"
204+
echo " --pip3 use pip3 [default: pip]"
204205
echo ""
205206
}
206207

@@ -233,9 +234,9 @@ f_remove_files() {
233234

234235
#=============================================================================
235236
# Check Visual Python files
236-
# 1 = Jupyterr Extension is not actived
237-
# 2 = visualpython does not exist
238-
# 3 = visualpython exists
237+
# 1 = Jupyterr Extension is not actived
238+
# 2 = visualpython does not exist
239+
# 3 = visualpython exists
239240
#=============================================================================
240241
f_check_extension() {
241242
if [ ! -e ${PATH_DST} ]; then
@@ -247,6 +248,31 @@ f_check_extension() {
247248
fi
248249
}
249250

251+
#=============================================================================
252+
# Get string(Version or Location) from pip show
253+
# $1 = Version or Location
254+
#=============================================================================
255+
f_get_string_pipshow() {
256+
RESULT="EMPTY"
257+
if [ $# -ge 1 ]; then
258+
RESULT=`${PIP} show ${VP_NAME} | grep $1 | awk -F':' '{print $2}' | tr -d ' '`
259+
fi
260+
echo ${RESULT}
261+
}
262+
263+
#=============================================================================
264+
# Get string(Jupyter nbextension path) from conda-env or jupyter
265+
#=============================================================================
266+
f_get_extension_path() {
267+
RESULT="EMPTY"
268+
if which conda-env > /dev/null 2>&1; then
269+
RESULT=`conda-env list | grep "*" | awk '{print $NF}'|tr -d ' '`/share/jupyter/nbextensions
270+
else
271+
RESULT=`jupyter --data-dir`/nbextensions
272+
fi
273+
echo ${RESULT}
274+
}
275+
250276
#=============================================================================
251277
# Print extension is not installed
252278
#=============================================================================

0 commit comments

Comments
 (0)