From 33108ec6c171dd1785d405d1abcf8ff1ca57f39e Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Tue, 1 Mar 2016 21:21:37 +0100 Subject: [PATCH] src/shell: add initial support for a LISA shell The LISA shell provides a set of useful alias and commands for commonly used operations. This intial implementation provides support for: - Submodules update - IPython server start/stop - Results reporting Signed-off-by: Patrick Bellasi --- LisaShell.txt | 28 +++++ init_env | 58 +++++---- ipynb/ipyserver_start | 61 --------- ipynb/ipyserver_stop | 4 - src/shell/lisa_colors | 55 +++++++++ src/shell/lisa_shell | 281 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 398 insertions(+), 89 deletions(-) create mode 100644 LisaShell.txt delete mode 100755 ipynb/ipyserver_start delete mode 100755 ipynb/ipyserver_stop create mode 100644 src/shell/lisa_colors create mode 100644 src/shell/lisa_shell diff --git a/LisaShell.txt b/LisaShell.txt new file mode 100644 index 000000000..23e5b797d --- /dev/null +++ b/LisaShell.txt @@ -0,0 +1,28 @@ + +All LISA Shell commands start with "lisa-", thus using shell completion it is +easy to get a list of all the available commands. + +Here is a list of the main ones, with a short description. +For a longer description type "lisa- help" + +.:: Generic commands +-------------------- + +lisa-help - Print this help, or command specific helps +lisa-version - Dump info on the LISA in use + +.:: Maintenance commands +------------------------ + +lisa-update - Update submodules and LISA notebooks/tests + +.:: Notebooks commands +---------------------- + +lisa-ipython - Start/Stop the IPython Notebook server + +.:: Results analysis and Documentation +-------------------------------------- + +lisa-report - Pretty format results of last test + diff --git a/init_env b/init_env index 0bc4fb8f2..d5119ab97 100644 --- a/init_env +++ b/init_env @@ -1,27 +1,37 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2015, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -# By default use internal libraries -DEVMODE=${DEVMODE:-1} - -export PYTHONPATH='' -export PYTHONPATH=`pwd`/libs/utils:$PYTHONPATH -export PYTHONPATH=`pwd`/libs/wlgen:$PYTHONPATH - -if [[ "x$DEVMODE" == "x1" ]]; then - export PYTHONPATH=`pwd`/libs/devlib:$PYTHONPATH - export PYTHONPATH=`pwd`/libs/trappy:$PYTHONPATH - export PYTHONPATH=`pwd`/libs/bart:$PYTHONPATH - - echo - echo 'Developer mode ENABLED, using libraries provided by:' - echo -e " ${PYTHONPATH//:/\\n }" - echo - - echo 'Checking for sumbmodules updates required...' - git submodule update --init - echo 'DONE' - - echo - echo 'Current submoule status:' - git submodule status +# LISA Shell: Initialization +grep "bash" /proc/$$/cmdline &>/dev/null +if [ $? -eq 0 ]; then + source ./src/shell/lisa_shell +else + echo "WARNING: Current shell is not a BASH" + # Check if a bash shell is available + which bash &>/dev/null + if [ $? -eq 0 ]; then + # Switch to a BASH shell + exec bash --init-file ./init_env + else + echo "ERROR: A BASH shell is not available in PATH" + fi + # It's up to the user to install a BASH + echo "The LISA shell requires a BASH shell." + echo "Please, source this configuration from a terminal running BASH." fi diff --git a/ipynb/ipyserver_start b/ipynb/ipyserver_start deleted file mode 100755 index 60ff7ded2..000000000 --- a/ipynb/ipyserver_start +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -NETIF=${1:-eth0} - -# By default use internal libraries -DEVMODE=${DEVMODE:-1} - -# Get the IP Address of the local Ethernet interface -IPADDR=$(ifconfig $NETIF 2>/dev/null | \ - awk '/inet / {print $2}' | \ - sed 's/addr://') - -if [ "x$IPADDR" == "x" ]; then - echo - echo "$NETIF is not a valid network interface" - echo - echo "Usage: $0 " - echo " NETIF - The network interface to start the server on" - echo - exit 1 -fi - -# Get base installation path of LISA -cd "$(dirname $0)/.." &>/dev/null -LISA_HOME="$(pwd)" -cd - $>/dev/null -PYDIR="$LISA_HOME/ipynb" -LOGFILE="$PYDIR/server.log" - -export PYTHONPATH='' -export PYTHONPATH=$LISA_HOME/libs/utils:$PYTHONPATH -export PYTHONPATH=$LISA_HOME/libs/wlgen:$PYTHONPATH - -if [ "x$DEVMODE" == "x1" ]; then - export PYTHONPATH=$LISA_HOME/libs/devlib:$PYTHONPATH - export PYTHONPATH=$LISA_HOME/libs/trappy:$PYTHONPATH - export PYTHONPATH=$LISA_HOME/libs/bart:$PYTHONPATH - - echo - echo 'Developer mode ENABLED, using local libraries' - if [ ! -f libs/devlib/README.rst ]; then - echo 'Initializing submodules...' - git submodule init - fi - echo 'Update submodules if required' - git submodule update - echo 'DONE' -fi - -echo 'Starting IPython Notebook server...' -echo " IP Address : http://$IPADDR:8888/" -echo ' Folder : ' $PYDIR -echo ' Logfile : ' $LOGFILE -echo ' PYTHONPATH : ' -echo -e "\t${PYTHONPATH//:/\\n\\t}" - -cd $PYDIR -nohup ipython notebook --ip=$IPADDR &>$LOGFILE & -cd - >/dev/null -echo - diff --git a/ipynb/ipyserver_stop b/ipynb/ipyserver_stop deleted file mode 100755 index 3f0e14826..000000000 --- a/ipynb/ipyserver_stop +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -killall ipython - diff --git a/src/shell/lisa_colors b/src/shell/lisa_colors new file mode 100644 index 000000000..2b4a7fdf0 --- /dev/null +++ b/src/shell/lisa_colors @@ -0,0 +1,55 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2015, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# LISA Shell: colors +# +# Define a set of useful console color escapes +# Other colors could be obtained using this syntax: +# \033[COLOR1;COLOR2m +# where COLOR1 and COLOR2 are Fore/Background: +# Color Fg Bg +# black 30 40 +# red 31 41 +# green 32 42 +# yellow 33 43 +# blue 34 44 +# magenta 35 45 +# cyan 36 46 +# white 37 47 + +LISASHELL_WHITE="\033[1;37m" +LISASHELL_LGRAY="\033[37m" +LISASHELL_GRAY="\033[1;30m" +LISASHELL_BLACK="\033[30m" +LISASHELL_RED="\033[31m" +LISASHELL_LRED="\033[1;31m" +LISASHELL_GREEN="\033[32m" +LISASHELL_LGREEN="\033[1;32m" +LISASHELL_BROWN="\033[33m" +LISASHELL_YELLOW="\033[1;33m" +LISASHELL_BLUE="\033[34m" +LISASHELL_LBLUE="\033[1;34m" +LISASHELL_PURPLE="\033[35m" +LISASHELL_PINK="\033[1;35m" +LISASHELL_CYAN="\033[36m" +LISASHELL_LCYAN="\033[1;36m" + +LISASHELL_RESET="\033[0m" +LISASHELL_DEFAULT=$LISASHELL_WHITE + +# vim: set tabstop=4: diff --git a/src/shell/lisa_shell b/src/shell/lisa_shell new file mode 100644 index 000000000..4caaaa3ac --- /dev/null +++ b/src/shell/lisa_shell @@ -0,0 +1,281 @@ +# +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright (C) 2015, ARM Limited and contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# LISA Shell: the Linux Integrated System Analysis Shell + +# Setup colors +source src/shell/lisa_colors + +# By default use internal libraries +DEVMODE=${DEVMODE:-1} + +# Get base installation path of LISA +LISA_HOME="$(pwd)" + +export PYTHONPATH='' +export PYTHONPATH=$LISA_HOME/libs/utils:$PYTHONPATH +export PYTHONPATH=$LISA_HOME/libs/wlgen:$PYTHONPATH + +if [ "x$DEVMODE" == "x1" ]; then + export PYTHONPATH=$LISA_HOME/libs/devlib:$PYTHONPATH + export PYTHONPATH=$LISA_HOME/libs/trappy:$PYTHONPATH + export PYTHONPATH=$LISA_HOME/libs/bart:$PYTHONPATH +fi + +################################################################################ +# Generic LISA Shell commands +################################################################################ + +# LISA Shell On-Line HELP +function lisa-help { +clear +echo -ne '\E[37;42m' +echo " " +echo " .:: LISA Shell - HELP On-Line ::. " +echo " " +echo -ne "$LISASHELL_RESET$LISASHELL_GREEN" +cat LisaShell.txt +echo -ne "$LISASHELL_DEFAULT" +} + +function lisa-version { +echo -ne "$LISASHELL_GREEN" +cat < .git/config.clean + cp .git/config.clean .git/config + # Force update existing modules + echo + echo 'Developer mode ENABLED, updating local libraries...' + git submodule update --init + echo 'DONE' +fi +echo -ne "$LISASHELL_DEFAULT" +} + +function lisa-update { +CMD=${1:-all} +echo +case "x${CMD^^}" in +'xALL') + _lisa-update-all + ;; +"xHELP"|*) + _lisa-update-usage + ;; +esac +echo +echo +} + +################################################################################ +# LISA Notebooks utility functions +################################################################################ + +function _lisa-ipython-usage { + echo "Usage: lisa-ipython CMD [NETIF]" + echo " CMD - IPython Notebooks command (deafult: start)" + echo " start start the ipython server" + echo " stop stop the ipython server" + echo " NETIF - the network interface to start the server on (default: lo)" +} + +function _lisa-ipython-start { +# Get IP address for the specified interface +IPADDR=$(ifconfig $NETIF 2>/dev/null | \ + awk '/inet / {print $2}' | \ + sed 's/addr://') +if [ "x$IPADDR" == "x" ]; then + echo + echo "$NETIF is not a valid network interface" + echo + echo "Usage: $0 " + echo " NETIF - The network interface to start the server on" + echo + exit 1 +fi +# Setup paths +PYDIR="$LISA_HOME/ipynb" +LOGFILE="$PYDIR/server.log" +PIDFILE="$PYDIR/server.pid" +# Check if an instance is already running +if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then + echo "Server already running, opening new window in browser" + xdg-open "http://$IPADDR:8888/" + return 1 +fi +# Start the server bindeed to the specified interface +echo 'Starting IPython Notebook server...' +echo " IP Address : http://$IPADDR:8888/" +echo ' Folder : ' $PYDIR +echo ' Logfile : ' $LOGFILE +echo ' PYTHONPATH : ' +echo -e "\t${PYTHONPATH//:/\\n\\t}" +cd $PYDIR +echo +echo -n 'Notebook server task: ' +nohup ipython notebook --ip=$IPADDR &>$LOGFILE & +echo $! >$PIDFILE +cd - >/dev/null +} + +function _lisa-ipython-stop { +PYDIR="$LISA_HOME/ipynb" +PIDFILE="$PYDIR/server.pid" +if [ -f "$PIDFILE" ] && pgrep -F $PIDFILE >/dev/null; then + kill $(<$PIDFILE) 2>/dev/null +fi +rm -f $PIDFILE 2>/dev/null +} + +function lisa-ipython { +CMD=${1:-start} +NETIF=${2:-lo} +echo +case "x${CMD^^}" in +'xSTART') + echo "Starting IPython Notebooks..." + _lisa-ipython-start $NETIF + ;; +'xSTOP') + echo "Stopping IPython Notebooks..." + _lisa-ipython-stop + ;; +"xHELP"|*) + _lisa-ipython-usage + ;; +esac +echo +echo +} + +################################################################################ +# LISA Tests utility functions +################################################################################ + +function _lisa-test-usage { +cat <