From ba02f69f0f0096ca3e8d55e5d42bca641a57127b Mon Sep 17 00:00:00 2001 From: mistangl Date: Wed, 28 Jan 2026 21:24:40 +0100 Subject: [PATCH] Shellskripte auch angepasst --- bin/draw_dxf.sh | 20 ++++++++++++++--- bin/getexdraw.sh | 9 ++++---- bin/getpositions.sh | 21 +++++++++++++---- bin/install_py.sh | 3 ++- bin/ioconverter.sh | 7 +++--- bin/manage_interpreter.sh | 47 ++++++++++++++++++++++++++++++--------- bin/portalexport.sh | 20 ++++++++++++++--- bin/routing.sh | 20 ++++++++++++++--- bin/run_test.sh | 19 +++++++++++++--- 9 files changed, 132 insertions(+), 34 deletions(-) diff --git a/bin/draw_dxf.sh b/bin/draw_dxf.sh index cbb9b2d..add3f73 100755 --- a/bin/draw_dxf.sh +++ b/bin/draw_dxf.sh @@ -1,4 +1,18 @@ #!/bin/bash -source manage_interpreter.sh activate_interpreter -python "$PROJECT_LIB/drawdxf.py" "$@" -source manage_interpreter.sh deactivate_interpreter + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/manage_interpreter.sh" activate + +if [ $? -ne 0 ]; then + echo "ERROR: Failed to activate Python environment" + exit 1 +fi + +pushd "$PROJECT" > /dev/null + +"$VIRTUAL_ENV/bin/python" -m lib.drawdxf "$@" +PYTHON_EXIT=$? + +popd > /dev/null +source "$SCRIPT_DIR/manage_interpreter.sh" deactivate +exit $PYTHON_EXIT diff --git a/bin/getexdraw.sh b/bin/getexdraw.sh index cc453fa..16e2260 100644 --- a/bin/getexdraw.sh +++ b/bin/getexdraw.sh @@ -21,11 +21,12 @@ ERROR_DOUBLE="${FILENAME}_errors.json" EXCEL_RES="${FILENAME}_cables.xlsx" DXF_RES="${FILENAME}_cables.dxf" -source $HOME/dxf-calculator/kabellaengen/bin/setenv.sh +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/setenv.sh" echo echo "=== Fetching Positions ===" -./getpositions.sh --filename "$1" -s -r -w "$JSON_POS" -e "$ERROR_DOUBLE" +"$SCRIPT_DIR/getpositions.sh" --filename "$1" -s -r -w "$JSON_POS" -e "$ERROR_DOUBLE" if [ -f "$PROJECT_WORK/$ERROR_DOUBLE" ]; then echo "-failed- duplicate IDs in given layout" @@ -42,7 +43,7 @@ fi echo echo "=== Creating Graph for Routing ===" -./routing.sh --filename "$JSON_POS" -w "$JSON_TODRAW" +"$SCRIPT_DIR/routing.sh" --filename "$JSON_POS" -w "$JSON_TODRAW" if [ ! -f "$PROJECT_WORK/$JSON_TODRAW" ]; then echo "-failed- routing" @@ -52,7 +53,7 @@ fi echo echo "=== Writing Output Files ===" -./draw_dxf.sh --filename "$JSON_TODRAW" --new "$DXF_RES" -x "$EXCEL_RES" +"$SCRIPT_DIR/draw_dxf.sh" --filename "$JSON_TODRAW" --new "$DXF_RES" -x "$EXCEL_RES" if [ ! -f "$PROJECT_WORK/$EXCEL_RES" ]; then echo "-failed- draw_dxf" diff --git a/bin/getpositions.sh b/bin/getpositions.sh index a53e515..c0e0a96 100755 --- a/bin/getpositions.sh +++ b/bin/getpositions.sh @@ -1,6 +1,19 @@ #!/bin/bash # getpositions.sh -#!/bin/bash -source manage_interpreter.sh activate_interpreter -python "$PROJECT_LIB/getpositions.py" "$@" -source manage_interpreter.sh deactivate_interpreter + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/manage_interpreter.sh" activate + +if [ $? -ne 0 ]; then + echo "ERROR: Failed to activate Python environment" + exit 1 +fi + +pushd "$PROJECT" > /dev/null + +"$VIRTUAL_ENV/bin/python" -m lib.getpositions "$@" +PYTHON_EXIT=$? + +popd > /dev/null +source "$SCRIPT_DIR/manage_interpreter.sh" deactivate +exit $PYTHON_EXIT diff --git a/bin/install_py.sh b/bin/install_py.sh index 9b296e7..925855a 100755 --- a/bin/install_py.sh +++ b/bin/install_py.sh @@ -1,5 +1,6 @@ #!/bin/bash -source setenv.sh +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/setenv.sh" if [ ! -d "$PROJECT/.venv" ]; then echo "Initialisiere Python virtual environment..." diff --git a/bin/ioconverter.sh b/bin/ioconverter.sh index 9ea2236..40c49bb 100755 --- a/bin/ioconverter.sh +++ b/bin/ioconverter.sh @@ -13,7 +13,8 @@ INPUT_FILE="$1" FILENAME=$(basename "$INPUT_FILE" .dxf) DIR=$(dirname "$INPUT_FILE") -source $HOME/dxf-calculator/kabellaengen/bin/setenv.sh +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/setenv.sh" # Namen der Zwischenergebnis Dateien JSON_POS="${FILENAME}_positionsconv.json" @@ -24,7 +25,7 @@ RESULT_TIA="${FILENAME}-*_TIA.xlsx" echo echo "=== Fetching Positions ===" -./getpositions.sh --filename "$1" -s -r -w "$JSON_POS" -e "$ERROR_DOUBLE" +"$SCRIPT_DIR/getpositions.sh" --filename "$1" -s -r -w "$JSON_POS" -e "$ERROR_DOUBLE" if [ -f "$PROJECT_WORK/$ERROR_DOUBLE" ]; then echo "== failed: duplicate IDs in given layout" @@ -40,7 +41,7 @@ if [ ! -f "$PROJECT_WORK/$JSON_POS" ]; then fi echo "=== Creating Excel Files for TIA, WSCAD, .. ===" -./portalexport.sh --filename "$JSON_POS" --outname "$FILENAME" +"$SCRIPT_DIR/portalexport.sh" --filename "$JSON_POS" --outname "$FILENAME" if [ ! -f "$PROJECT_WORK/$RESULT_TIA" ]; then echo "== failed: creating .xlsx files" diff --git a/bin/manage_interpreter.sh b/bin/manage_interpreter.sh index 501fed0..d814ccf 100755 --- a/bin/manage_interpreter.sh +++ b/bin/manage_interpreter.sh @@ -1,30 +1,57 @@ #!/bin/bash -activate_interpreter() { +# Source setenv.sh if not already loaded +if [ -z "$PROJECT" ]; then + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "$SCRIPT_DIR/setenv.sh" +fi + +activate() { + # Choose Python interpreter + if [ -n "$NETWORK_PYTHON" ]; then + PYTHON_EXE="$NETWORK_PYTHON/bin/python" + else + PYTHON_EXE="python3" + fi + + # Ensure venv exists + if [ ! -d "$PROJECT/.venv" ]; then + echo "Creating virtual environment..." + "$PYTHON_EXE" -m venv "$PROJECT/.venv" + if [ $? -ne 0 ]; then + echo "ERROR: Failed to create virtual environment" + return 1 + fi + fi + + # Activate venv if [ -f "$PROJECT/.venv/bin/activate" ]; then source "$PROJECT/.venv/bin/activate" + # Pin the interpreter + export VIRTUAL_ENV_PYTHON="$PYTHON_EXE" else - echo "Virtual environment not found. Run install_py.sh first." - exit 1 + echo "ERROR: Virtual environment activation script not found" + return 1 fi } -deactivate_interpreter() { +deactivate() { if [ -n "$VIRTUAL_ENV" ]; then - deactivate + deactivate 2>/dev/null || true + unset VIRTUAL_ENV_PYTHON fi } # Call function based on argument case "$1" in - activate_interpreter) - activate_interpreter + activate|activate_interpreter) + activate ;; - deactivate_interpreter) - deactivate_interpreter + deactivate|deactivate_interpreter) + deactivate ;; *) - echo "Usage: $0 {activate_interpreter|deactivate_interpreter}" + echo "Usage: $0 {activate|deactivate|activate_interpreter|deactivate_interpreter}" exit 1 ;; esac diff --git a/bin/portalexport.sh b/bin/portalexport.sh index ff237ad..1b364cd 100644 --- a/bin/portalexport.sh +++ b/bin/portalexport.sh @@ -1,4 +1,18 @@ #!/bin/bash -source manage_interpreter.sh activate_interpreter -python "$PROJECT_LIB/portalexport.py" "$@" -source manage_interpreter.sh deactivate_interpreter + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/manage_interpreter.sh" activate + +if [ $? -ne 0 ]; then + echo "ERROR: Failed to activate Python environment" + exit 1 +fi + +pushd "$PROJECT" > /dev/null + +"$VIRTUAL_ENV/bin/python" -m lib.portalexport "$@" +PYTHON_EXIT=$? + +popd > /dev/null +source "$SCRIPT_DIR/manage_interpreter.sh" deactivate +exit $PYTHON_EXIT diff --git a/bin/routing.sh b/bin/routing.sh index 24779dc..6849a60 100755 --- a/bin/routing.sh +++ b/bin/routing.sh @@ -1,4 +1,18 @@ #!/bin/bash -source manage_interpreter.sh activate_interpreter -python "$PROJECT_LIB/routing.py" "$@" -source manage_interpreter.sh deactivate_interpreter + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/manage_interpreter.sh" activate + +if [ $? -ne 0 ]; then + echo "ERROR: Failed to activate Python environment" + exit 1 +fi + +pushd "$PROJECT" > /dev/null + +"$VIRTUAL_ENV/bin/python" -m lib.routing "$@" +PYTHON_EXIT=$? + +popd > /dev/null +source "$SCRIPT_DIR/manage_interpreter.sh" deactivate +exit $PYTHON_EXIT diff --git a/bin/run_test.sh b/bin/run_test.sh index 504da81..73d94e6 100644 --- a/bin/run_test.sh +++ b/bin/run_test.sh @@ -92,12 +92,25 @@ echo "Test-Parameter: $TEST_PARAMS" echo "============================================================================" echo "" -# Wechsle ins Projektverzeichnis und führe run_tests.py aus -cd "$PROJECT" -python "$PROJECT_LIB/run_tests.py" $TEST_PARAMS +# Python-Umgebung aktivieren +source "$SCRIPT_DIR/manage_interpreter.sh" activate +if [ $? -ne 0 ]; then + echo "ERROR: Failed to activate Python environment" + exit 1 +fi + +# Wechsle ins Projektverzeichnis und führe run_tests.py aus +pushd "$PROJECT" > /dev/null + +"$VIRTUAL_ENV/bin/python" -m lib.run_tests $TEST_PARAMS TEST_RESULT=$? +popd > /dev/null + +# Python-Umgebung deaktivieren +source "$SCRIPT_DIR/manage_interpreter.sh" deactivate + echo "" echo "============================================================================" if [ $TEST_RESULT -eq 0 ]; then