From bfb03af2c811f4a9411d9ca288a1c4a0030a1ea2 Mon Sep 17 00:00:00 2001 From: Ganesh Gore Date: Sat, 16 Nov 2019 15:52:32 -0700 Subject: [PATCH] Added run-task and run-flow functions --- openfpga.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/openfpga.sh b/openfpga.sh index fdf591a7c..e44b22f82 100755 --- a/openfpga.sh +++ b/openfpga.sh @@ -6,7 +6,9 @@ #============================================================================== export OPENFPGA_PATH="$(pwd)" +export OPENFPGA_SCRIPT_PATH="$(pwd)/openfpga_flow/scripts" export OPENFPGA_TASK_PATH="$(pwd)/openfpga_flow/tasks" +if [ -z $PYTHON_EXEC ]; then export PYTHON_EXEC="python3"; fi # This function checks the path and # raises warning if the command is not executing @@ -17,6 +19,14 @@ check_execution_path (){ fi } +run-task () { + $PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@" +} + +run-flow () { + $PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_flow.py "$@" +} + # lists all the configure task in task directory list-tasks () { check_execution_path "$(pwd)" @@ -35,22 +45,30 @@ goto-task () { return fi goto_path=$OPENFPGA_TASK_PATH/$1 - run_num="latest" + run_num="" if [ ! -d $goto_path ]; then echo "Task directory not found"; return; fi - if [[ $2 == '^[0-9]+$' ]] ; then - echo "Second argumetn provided" - if ! [[ $2 == '0' ]] ; then run_num="$(printf run%03d $2)" else run_num="latest" fi - if [ ! -d "$goto_path/$run_num" ]; then run_num="latest" fi + if [[ "$2" =~ '^[0-9]+$' ]] ; then + if ! [[ $2 == '0' ]] ; then run_num="$(printf run%03d $2)"; else run_num="latest"; fi + if [ ! -d "$goto_path/$run_num" ]; then run_num="latest"; fi fi if [ ! -d $goto_path/$run_num ]; then - echo "\e[33mTask run directory not found -" $goto_path/$run_num "\e[0m"; + echo "\e[33mTask run directory not found -" $goto_path/$run_num "\e[0m" else + echo "Switching current dirctory to" $goto_path/$run_num cd $goto_path/$run_num fi } # Clears enviroment variables and fucntions -unset_openfpga (){ +unset-openfpga (){ unset -v OPENFPGA_PATH - unset -f list-tasks goto-task goto-root >/dev/null 2>&1 -} \ No newline at end of file + unset -f list-tasks run-task run-flow goto-task goto-root >/dev/null 2>&1 +} + +# Allow autocompletion of task +if [[ $(ps -p $$ -oargs=) == *"zsh"* ]]; then + autoload -U +X bashcompinit; bashcompinit; +fi +TaskList=$(ls -tdalh ${OPENFPGA_TASK_PATH}/* | awk '{system("basename " $9)}' | awk '{printf("%s ",$1)}') +complete -W "${TaskList}" goto-task +complete -W "${TaskList}" run-task \ No newline at end of file