Shellskripte auch angepasst

This commit is contained in:
2026-01-28 21:24:40 +01:00
parent e087b65359
commit ba02f69f0f
9 changed files with 132 additions and 34 deletions
+17 -3
View File
@@ -1,4 +1,18 @@
#!/bin/bash #!/bin/bash
source manage_interpreter.sh activate_interpreter
python "$PROJECT_LIB/drawdxf.py" "$@" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source manage_interpreter.sh deactivate_interpreter 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
+5 -4
View File
@@ -21,11 +21,12 @@ ERROR_DOUBLE="${FILENAME}_errors.json"
EXCEL_RES="${FILENAME}_cables.xlsx" EXCEL_RES="${FILENAME}_cables.xlsx"
DXF_RES="${FILENAME}_cables.dxf" 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
echo "=== Fetching Positions ===" 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 if [ -f "$PROJECT_WORK/$ERROR_DOUBLE" ]; then
echo "-failed- duplicate IDs in given layout" echo "-failed- duplicate IDs in given layout"
@@ -42,7 +43,7 @@ fi
echo echo
echo "=== Creating Graph for Routing ===" 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 if [ ! -f "$PROJECT_WORK/$JSON_TODRAW" ]; then
echo "-failed- routing" echo "-failed- routing"
@@ -52,7 +53,7 @@ fi
echo echo
echo "=== Writing Output Files ===" 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 if [ ! -f "$PROJECT_WORK/$EXCEL_RES" ]; then
echo "-failed- draw_dxf" echo "-failed- draw_dxf"
+17 -4
View File
@@ -1,6 +1,19 @@
#!/bin/bash #!/bin/bash
# getpositions.sh # getpositions.sh
#!/bin/bash
source manage_interpreter.sh activate_interpreter SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
python "$PROJECT_LIB/getpositions.py" "$@" source "$SCRIPT_DIR/manage_interpreter.sh" activate
source manage_interpreter.sh deactivate_interpreter
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
+2 -1
View File
@@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
source setenv.sh SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/setenv.sh"
if [ ! -d "$PROJECT/.venv" ]; then if [ ! -d "$PROJECT/.venv" ]; then
echo "Initialisiere Python virtual environment..." echo "Initialisiere Python virtual environment..."
+4 -3
View File
@@ -13,7 +13,8 @@ INPUT_FILE="$1"
FILENAME=$(basename "$INPUT_FILE" .dxf) FILENAME=$(basename "$INPUT_FILE" .dxf)
DIR=$(dirname "$INPUT_FILE") 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 # Namen der Zwischenergebnis Dateien
JSON_POS="${FILENAME}_positionsconv.json" JSON_POS="${FILENAME}_positionsconv.json"
@@ -24,7 +25,7 @@ RESULT_TIA="${FILENAME}-*_TIA.xlsx"
echo echo
echo "=== Fetching Positions ===" 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 if [ -f "$PROJECT_WORK/$ERROR_DOUBLE" ]; then
echo "== failed: duplicate IDs in given layout" echo "== failed: duplicate IDs in given layout"
@@ -40,7 +41,7 @@ if [ ! -f "$PROJECT_WORK/$JSON_POS" ]; then
fi fi
echo "=== Creating Excel Files for TIA, WSCAD, .. ===" 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 if [ ! -f "$PROJECT_WORK/$RESULT_TIA" ]; then
echo "== failed: creating .xlsx files" echo "== failed: creating .xlsx files"
+37 -10
View File
@@ -1,30 +1,57 @@
#!/bin/bash #!/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 if [ -f "$PROJECT/.venv/bin/activate" ]; then
source "$PROJECT/.venv/bin/activate" source "$PROJECT/.venv/bin/activate"
# Pin the interpreter
export VIRTUAL_ENV_PYTHON="$PYTHON_EXE"
else else
echo "Virtual environment not found. Run install_py.sh first." echo "ERROR: Virtual environment activation script not found"
exit 1 return 1
fi fi
} }
deactivate_interpreter() { deactivate() {
if [ -n "$VIRTUAL_ENV" ]; then if [ -n "$VIRTUAL_ENV" ]; then
deactivate deactivate 2>/dev/null || true
unset VIRTUAL_ENV_PYTHON
fi fi
} }
# Call function based on argument # Call function based on argument
case "$1" in case "$1" in
activate_interpreter) activate|activate_interpreter)
activate_interpreter activate
;; ;;
deactivate_interpreter) deactivate|deactivate_interpreter)
deactivate_interpreter deactivate
;; ;;
*) *)
echo "Usage: $0 {activate_interpreter|deactivate_interpreter}" echo "Usage: $0 {activate|deactivate|activate_interpreter|deactivate_interpreter}"
exit 1 exit 1
;; ;;
esac esac
+17 -3
View File
@@ -1,4 +1,18 @@
#!/bin/bash #!/bin/bash
source manage_interpreter.sh activate_interpreter
python "$PROJECT_LIB/portalexport.py" "$@" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source manage_interpreter.sh deactivate_interpreter 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
+17 -3
View File
@@ -1,4 +1,18 @@
#!/bin/bash #!/bin/bash
source manage_interpreter.sh activate_interpreter
python "$PROJECT_LIB/routing.py" "$@" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source manage_interpreter.sh deactivate_interpreter 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
+16 -3
View File
@@ -92,12 +92,25 @@ echo "Test-Parameter: $TEST_PARAMS"
echo "============================================================================" echo "============================================================================"
echo "" echo ""
# Wechsle ins Projektverzeichnis und führe run_tests.py aus # Python-Umgebung aktivieren
cd "$PROJECT" source "$SCRIPT_DIR/manage_interpreter.sh" activate
python "$PROJECT_LIB/run_tests.py" $TEST_PARAMS
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=$? TEST_RESULT=$?
popd > /dev/null
# Python-Umgebung deaktivieren
source "$SCRIPT_DIR/manage_interpreter.sh" deactivate
echo "" echo ""
echo "============================================================================" echo "============================================================================"
if [ $TEST_RESULT -eq 0 ]; then if [ $TEST_RESULT -eq 0 ]; then