Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 90 additions & 64 deletions bin/visualpy
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,9 @@
# Change Date :
#

#=============================================================================
# Set variable
#=============================================================================
PIP=pip
JP_NB='jupyter nbextension'

VP_NAME='visualpython'
VP_BIND='visualpython/src/main'

PIP_UNINST=${PIP}' uninstall '${VP_NAME}
PIP_UPGRAD=${PIP}' install '${VP_NAME}' --upgrade'

VP_VERSION=`${PIP} show ${VP_NAME} | grep Version | awk -F':' '{print $2}' | tr -d ' '`
PATH_SRC=`${PIP} show ${VP_NAME} | grep Location | awk -F':' '{print $2}' | tr -d ' '`

# Set PATH_DST: nbextensions
if which conda-env > /dev/null 2>&1; then
PATH_DST=`conda-env list | grep "*" | awk '{print $NF}'|tr -d ' '`/share/jupyter/nbextensions
else
PATH_DST=`jupyter --data-dir`/nbextensions
fi

#=============================================================================
# Check Arguments
# - set VP_OPTION & PIP_T
#=============================================================================
if [ $# -eq 1 ]; then
VP_OPTION=$1
Expand All @@ -49,49 +28,65 @@ else
VP_OPTION=''
fi

which ${PIP_T}> /dev/null 2>&1 && PIP=${PIP_T}
#=============================================================================
# Set variable
#=============================================================================
PIP=pip
which ${PIP_T} > /dev/null 2>&1 && PIP=${PIP_T}

JP_NB='jupyter nbextension'

VP_NAME='visualpython'
VP_BIND='visualpython/src/main'

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)
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;;
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() {
V_RES=$(f_check_extension)
RES=`f_check_extension`
# 1 = Jupyterr Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists

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

if [ ${V_RES} -eq 1 ]; then
if [ ${RES} -eq 1 ]; then
f_print_not_extension
elif [ ${V_RES} -eq 2 ]; then
elif [ ${RES} -eq 2 ]; then
f_copy_files
f_enable
elif [ ${V_RES} -eq 3 ]; then
elif [ ${RES} -eq 3 ]; then
# overwrite
f_print_line1
echo "Already exists Visual Python."
Expand All @@ -108,16 +103,16 @@ f_install() {
# Uninstall Visual Python
#=============================================================================
f_uninstall() {
V_RES=$( f_check_extension )
RES=`f_check_extension`
# 1 = Jupyterr Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists

if [ ${V_RES} -eq 2 ]; then
if [ ${RES} -eq 2 ]; then
f_print_line2
${PIP_UNINST}
f_print_line2
elif [ ${V_RES} -eq 3 ]; then
elif [ ${RES} -eq 3 ]; then
f_print_line1
f_disable
f_print_line2
Expand All @@ -133,12 +128,16 @@ f_uninstall() {
#=============================================================================
f_upgrade() {
f_print_line1
echo "Running upgrade"
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=`${PIP} show ${VP_NAME} | grep Version | awk -F':' '{print $2}' | tr -d ' '`
VP_VERSION_NEW=`f_get_string_pipshow Version`

if [ ${VP_VERSION} = ${VP_VERSION_NEW} ]; then
f_print_line2
Expand All @@ -161,8 +160,8 @@ f_upgrade() {
# Enable Visual Python
#=============================================================================
f_enable() {
V_RES=$(f_check_extension)
if [ ${V_RES} -eq 3 ]; then
RES=`f_check_extension`
if [ ${RES} -eq 3 ]; then
${JP_NB} enable ${VP_BIND}
fi
}
Expand All @@ -171,8 +170,8 @@ f_enable() {
# Disable Visual Python
#=============================================================================
f_disable() {
V_RES=$(f_check_extension)
if [ ${V_RES} -eq 3 ]; then
RES=`f_check_extension`
if [ ${RES} -eq 3 ]; then
${JP_NB} disable ${VP_BIND}
fi
}
Expand All @@ -181,6 +180,8 @@ f_disable() {
# Visual Python version
#=============================================================================
f_version() {
VP_VERSION=`f_get_string_pipshow Version`

echo "Visual Python "${VP_VERSION}
}

Expand All @@ -189,18 +190,18 @@ f_version() {
#=============================================================================
f_help() {
echo ""
echo "usage: visualpy [option] | --pip3"
echo "usage: visualpy [option] [--pip3]"
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 " -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 " --pip3 use pip3 [default: pip]"
echo ""
}

Expand Down Expand Up @@ -233,9 +234,9 @@ f_remove_files() {

#=============================================================================
# Check Visual Python files
# 1 = Jupyterr Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists
# 1 = Jupyterr Extension is not actived
# 2 = visualpython does not exist
# 3 = visualpython exists
#=============================================================================
f_check_extension() {
if [ ! -e ${PATH_DST} ]; then
Expand All @@ -247,6 +248,31 @@ f_check_extension() {
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 '{print $NF}'|tr -d ' '`/share/jupyter/nbextensions
else
RESULT=`jupyter --data-dir`/nbextensions
fi
echo ${RESULT}
}

#=============================================================================
# Print extension is not installed
#=============================================================================
Expand Down
Loading