-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathvisualpy.bat
More file actions
335 lines (278 loc) · 10.3 KB
/
visualpy.bat
File metadata and controls
335 lines (278 loc) · 10.3 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
326
327
328
329
330
331
332
333
334
335
@echo off
SetLocal
rem #
rem # Project Name : Visual Python
rem # Description : GUI-based Python code generator
rem # File Name : visualpy.bat
rem # Author : Black Logic - LJ
rem # Note : Control Visual Python for windows
rem # License : GPLv3 (GNU General Public License v3.0)
rem # Date : 2021. 08. 14
rem # Change Date :
rem #
rem #=========================================================================
rem # Check Arguments
rem # - set VP_OPTION & PIP_T
rem #=========================================================================
set argc=0
for %%x in (%*) do Set /a argc+=1
if %argc% == 1 (
set VP_OPTION=%1
) else if %argc% == 2 (
set ARG1=%1
set ARG2=%2
) else (
set VP_OPTION=
)
if %argc% == 2 (
if "%ARG1:~0,2%" == "--" (
set VP_OPTION=%ARG2%
set PIP_T=%ARG1:~2%
) else (
set VP_OPTION=%ARG1%
set PIP_T=%ARG2:~2%
)
)
rem #=========================================================================
rem # Set variable
rem #=========================================================================
set PIP=pip
where %PIP_T% > nul 2>&1 && set PIP=%PIP_T%
set JP_NB=jupyter nbextension
set VP_NAME=visualpython
set VP_BIND=visualpython/visualpython
set PIP_UNINST=%PIP% uninstall %VP_NAME%
set PIP_UPGRAD=%PIP% install %VP_NAME% --upgrade
rem #=========================================================================
rem # main block
rem #=========================================================================
:f_main
echo Package install command: %PIP%
IF /i "%VP_OPTION%"=="" goto :f_help
for %%i in (-v version) do if /i %VP_OPTION% == %%i goto :f_version
for %%i in (-h help) do if /i %VP_OPTION% == %%i goto :f_help
call :f_get_string_pipshow RES Location
set PATH_SRC=%RES%
call :f_get_extension_path RES
set PATH_DST=%RES%
for %%i in (-e enable) do if /i %VP_OPTION% == %%i goto :f_enable
for %%i in (-d disable) do if /i %VP_OPTION% == %%i goto :f_disable
for %%i in (-i install) do if /i %VP_OPTION% == %%i goto :f_install
for %%i in (-un uninstall) do if /i %VP_OPTION% == %%i goto :f_uninstall
for %%i in (-up upgrade) do if /i %VP_OPTION% == %%i goto :f_upgrade
goto :f_help
goto :eof
rem #=========================================================================
rem # Install Visual Python
rem #=========================================================================
:f_install
if not exist "%PATH_DST%" (
mkdir "%PATH_DST%"
)
call :f_check_extension RES
rem # 1 = Jupyter Extension is not actived
rem # 2 = visualpython does not exist
rem # 3 = visualpython exists
if %RES% == 1 (
call :f_print_not_extension
) else if %RES% == 2 (
call :f_copy_files
call :f_enable
) else if %RES% == 3 (
rem # overwrite
call :f_print_line1
echo Already exists Visual Python.
call :f_print_line1
call :f_disable
call :f_remove_files
call :f_copy_files
call :f_enable
)
goto :eof
rem #=========================================================================
rem # Uninstall Visual Python
rem #=========================================================================
:f_uninstall
call :f_check_extension RES
rem # 1 = Jupyter Extension is not actived
rem # 2 = visualpython does not exist
rem # 3 = visualpython exists
if %RES% == 2 (
call :f_print_line2
%PIP_UNINST%
call :f_print_line2
) else if %RES% == 3 (
call :f_print_line1
call :f_disable
call :f_print_line2
call :f_remove_files
call :f_print_line2
%PIP_UNINST%
call :f_print_line1
)
goto :eof
rem #=========================================================================
rem # Upgrade Visual Python
rem #=========================================================================
:f_upgrade
call :f_print_line1
echo Running upgrade Visual Python
call :f_print_line2
rem # Get Visual Python version
call :f_get_string_pipshow RES Version
set VP_VERSION=%RES%
%PIP_UPGRAD%
rem # Get Visual Python new version
call :f_get_string_pipshow RES Version
set VP_VERSION_NEW=%RES%
if "%VP_VERSION%" == "%VP_VERSION_NEW%" (
call :f_print_line2
echo Already installed last Visual Python version.
call :f_print_line2
echo Installed version : %VP_VERSION%
echo Last Release version : %VP_VERSION_NEW%
call :f_print_line1
) else (
call :f_print_line2
call :f_disable
call :f_remove_files
call :f_copy_files
call :f_enable
call :f_print_line1
)
goto :eof
rem #=========================================================================
rem # Enable Visual Python
rem #=========================================================================
:f_enable
call :f_check_extension RES
if %RES% == 3 %JP_NB% enable %VP_BIND%
goto :eof
rem #=========================================================================
rem # Disable Visual Python
rem #=========================================================================
:f_disable
call :f_check_extension RES
if %RES% == 3 %JP_NB% disable %VP_BIND%
goto :eof
rem #=========================================================================
rem # Visual Python version
rem #=========================================================================
:f_version
call :f_get_string_pipshow RES Version
set VP_VERSION=%RES%
echo Visual Python %VP_VERSION%
goto :eof
rem #=========================================================================
rem # Help messages
rem #=========================================================================
: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.
goto :eof
rem #=========================================================================
rem # Copy Visual Python files
rem #=========================================================================
:f_copy_files
call :f_print_line1
echo Copy visualpython extension files ...
call :f_print_line2
echo Source Dir : %PATH_SRC%\%VP_NAME%
echo Target Dir : %PATH_DST%\%VP_NAME%
call :f_print_line1
xcopy /q /y /e "%PATH_SRC%\%VP_NAME%" "%PATH_DST%\%VP_NAME%\"
goto :eof
rem #=========================================================================
rem # Remove Visual Python files
rem #=========================================================================
:f_remove_files
call :f_print_line1
echo Remove Visual Python Directories.
rmdir /s /q "%PATH_DST%\%VP_NAME%"
goto :eof
rem #=========================================================================
rem # Check Visual Python files
rem # 1 = Jupyter Extension is not actived
rem # 2 = visualpython does not exist
rem # 3 = visualpython exists
rem #=========================================================================
:f_check_extension
if not exist "%PATH_DST%" (
set %~1=1
) else if not exist "%PATH_DST%\%VP_NAME%" (
set %~1=2
) else (
set %~1=3
)
goto :eof
rem #=========================================================================
rem # Get string(Version or Location) from pip show
rem # %~2 = Version or Location
rem #=========================================================================
:f_get_string_pipshow
set BUF1=
set RESULT=EMPTY
for /f "delims=: tokens=1*" %%i in ('%PIP% show %VP_NAME% 2^>^&1 ^| find "%~2"') do (set BUF1=%%j)
set RESULT=%BUF1: =%
set %~1=%RESULT%
goto :eof
rem #=========================================================================
rem # Get string(Jupyter nbextension path) from conda-env or jupyter
rem #=========================================================================
:f_get_extension_path
set BUF1=
set BUF2=
set RESULT=EMPTY
where /q conda-env
if "%ERRORLEVEL%" == "0" (
for /f "delims=* tokens=2" %%i in ('conda-env list 2^>^&1 ^| find "*"') do (set BUF1=%%i)
) else (
for /f "tokens=*" %%i in ('jupyter --data-dir') do (set BUF2=%%i)
)
if not "%BUF1%" == "" (
set RESULT=%BUF1: =%\share\jupyter\nbextensions
) else (
set RESULT=%BUF2: =%\nbextensions
)
set %~1=%RESULT%
goto :eof
rem #=========================================================================
rem # Print extension is not installed
rem #=========================================================================
:f_print_not_extension
echo Jupyter nbextension is not activated
echo Please install Jupyter nbextension
call :f_print_line1
echo for conda env
echo conda install -c conda-forge jupyter_contrib_nbextensions
echo jupyter contrib nbextension install --user
call :f_print_line2
echo for pip
echo %PIP% install -e jupyter_contrib_nbextensions
echo jupyter contrib nbextension install --user
call :f_print_line1
goto :eof
rem #=========================================================================
rem # Print line
rem #=========================================================================
:f_print_line1
echo ==========================================================================================
goto :eof
:f_print_line2
echo ------------------------------------------------------------------------------------------
goto :eof
rem #=========================================================================
rem # End of file
EndLocal