2020-12-02 18:18:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-01-12 12:20:13 +01:00
|
|
|
SCRIPT_PATH="$0"
|
|
|
|
SCRIPT_NAME=$(basename "$SCRIPT_PATH")
|
2020-12-02 18:18:47 +01:00
|
|
|
VERSION="__VERSION__"
|
|
|
|
VENV_PATH="$HOME/.local/src/msspec_venv_$VERSION"
|
|
|
|
|
|
|
|
# Check venv path
|
|
|
|
if ! [ -d "$VENV_PATH" ]; then
|
|
|
|
echo "ERROR: Unable to find version $VERSION of msspec!!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
launch_script() {
|
|
|
|
. "$VENV_PATH/bin/activate" && python $@
|
|
|
|
}
|
|
|
|
|
|
|
|
show_help () {
|
|
|
|
echo "Usage: 1) $SCRIPT_NAME -p [PYTHON OPTIONS] SCRIPT [ARGUMENTS...]"
|
|
|
|
echo " 2) $SCRIPT_NAME [-l FILE | -i | -h]"
|
|
|
|
echo " 3) eval \$($SCRIPT_NAME -e)"
|
|
|
|
echo ""
|
|
|
|
echo "Form (1) is used to launch a script"
|
|
|
|
echo "Form (2) is used to load a hdf5 data file"
|
|
|
|
echo "Form (3) is used to activate the msspec virtual environment"
|
|
|
|
echo ""
|
|
|
|
echo "List of possible options:"
|
|
|
|
echo " -p Pass every arguments after this option to the msspec"
|
|
|
|
echo " virtual environment Python interpreter."
|
|
|
|
echo " -i Run the interactive Python interpreter within msspec"
|
|
|
|
echo " virtual environment."
|
|
|
|
echo " -l Load and display a *.hdf5 data file in a graphical"
|
|
|
|
echo " window."
|
2021-01-12 12:20:13 +01:00
|
|
|
echo " -v Print the version."
|
2020-12-02 18:18:47 +01:00
|
|
|
echo " -h Show this help message."
|
|
|
|
}
|
|
|
|
|
|
|
|
launch_interpreter() {
|
|
|
|
source $VENV_PATH/bin/activate
|
|
|
|
echo "Python interpreter of the MsSpec virtual environment."
|
|
|
|
echo ""
|
|
|
|
echo "This environment includes the following packages:"
|
|
|
|
pip list
|
|
|
|
echo ""
|
|
|
|
echo "Type in <CTRL>+D to exit."
|
|
|
|
echo ""
|
|
|
|
ipython --profile=msspec
|
|
|
|
}
|
|
|
|
|
|
|
|
load_data() {
|
|
|
|
. "$VENV_PATH/bin/activate" && python -m msspec.iodata $1
|
|
|
|
}
|
|
|
|
|
|
|
|
read_yes_no () {
|
|
|
|
PROMPT="$1"
|
|
|
|
DEFAULT="$2"
|
|
|
|
BYPASS="$3"
|
|
|
|
|
|
|
|
ANSWER=""
|
|
|
|
RESPONSE=""
|
|
|
|
|
|
|
|
VALID=1
|
|
|
|
while test $VALID -ne 0; do
|
|
|
|
test "$BYPASS" = "y" || read -p "${PROMPT} (y/n) [${DEFAULT}]? " "RESPONSE"
|
|
|
|
ANSWER="${RESPONSE:-${DEFAULT}}"
|
|
|
|
case "${ANSWER}" in
|
|
|
|
y|n) VALID=0 ;;
|
|
|
|
*) echo "Invalid choice, please answer \"y\" or \"n\"."; VALID=1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
uninstall() {
|
|
|
|
read_yes_no "This will completely remove msspec from your computer. Are you sure" "n" "$BYPASS"
|
|
|
|
case "${ANSWER}" in
|
2021-01-12 12:20:13 +01:00
|
|
|
y) rm -rv "$VENV_PATH" && rm "$SCRIPT_PATH" && echo "MsSpec successfully uninstalled." ;;
|
2020-12-02 18:18:47 +01:00
|
|
|
n) echo "Uninstallation aborted." ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-12 12:20:13 +01:00
|
|
|
while getopts "hvil:p:eu" option; do
|
2020-12-02 18:18:47 +01:00
|
|
|
case $option in
|
|
|
|
p) shift; launch_script "$@"
|
|
|
|
;;
|
|
|
|
i) launch_interpreter
|
|
|
|
;;
|
|
|
|
l) load_data "$OPTARG"; shift
|
|
|
|
;;
|
|
|
|
e) echo ". $VENV_PATH/bin/activate"
|
|
|
|
;;
|
|
|
|
u) uninstall
|
|
|
|
;;
|
2021-01-12 12:20:13 +01:00
|
|
|
v) echo $VERSION
|
|
|
|
;;
|
2020-12-02 18:18:47 +01:00
|
|
|
*|h) show_help
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $OPTIND -eq 1 ]; then
|
|
|
|
show_help
|
|
|
|
fi
|