From e087b65359da557b2b6ce30c49769974632311e4 Mon Sep 17 00:00:00 2001 From: mistangl Date: Wed, 28 Jan 2026 20:20:20 +0100 Subject: [PATCH] =?UTF-8?q?bat=20Dateien=20mit=20Errorlevel=20versehen.=20?= =?UTF-8?q?manage=5Finterpreter.bat=20vereinfacht.=20Nur=20noch=20eine=20U?= =?UTF-8?q?mgebungsvar=20f=C3=BCr=20den=20Python=20Interpreter=20im=20Netz?= =?UTF-8?q?werk.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/create_example.bat | 17 +++- bin/create_numbers.bat | 17 +++- bin/draw_dxf.bat | 17 +++- bin/getpositions.bat | 17 +++- bin/manage_interpreter.bat | 47 ++++++----- bin/portalexport.bat | 17 +++- bin/routing.bat | 17 +++- bin/run_test.bat | 17 +++- bin/run_tests.bat | 16 ++-- bin/setenv.bat | 6 +- bin/setenv.sh | 12 ++- bin/translate.bat | 17 +++- cfg/create_tests.json | 154 ++++++++++++++++++++++++++++++++++--- lib/create_example.py | 61 +++++++++++---- 14 files changed, 353 insertions(+), 79 deletions(-) diff --git a/bin/create_example.bat b/bin/create_example.bat index e446f0d..970c7fc 100644 --- a/bin/create_example.bat +++ b/bin/create_example.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\create_example.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.create_example %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/create_numbers.bat b/bin/create_numbers.bat index e7c2c1b..cc11e90 100644 --- a/bin/create_numbers.bat +++ b/bin/create_numbers.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\create_numbers.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.create_numbers %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/draw_dxf.bat b/bin/draw_dxf.bat index 16dd935..01621b2 100644 --- a/bin/draw_dxf.bat +++ b/bin/draw_dxf.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\drawdxf.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.drawdxf %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/getpositions.bat b/bin/getpositions.bat index 77d27d6..aaa6e07 100644 --- a/bin/getpositions.bat +++ b/bin/getpositions.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\getpositions.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.getpositions %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/manage_interpreter.bat b/bin/manage_interpreter.bat index 02d47a3..31c0280 100644 --- a/bin/manage_interpreter.bat +++ b/bin/manage_interpreter.bat @@ -1,30 +1,35 @@ @echo off CALL setenv.bat -IF DEFINED NETWORK_INTERPRETER_PATH ( - goto %~1_network +IF /I "%1"=="activate" GOTO activate +IF /I "%1"=="deactivate" GOTO deactivate +IF /I "%1"=="activate_interpreter" GOTO activate +IF /I "%1"=="deactivate_interpreter" GOTO deactivate +GOTO :eof + + +:activate +REM Interpreter wählen +IF DEFINED NETWORK_PYTHON ( + SET PYTHON_EXE=%NETWORK_PYTHON%\python.exe ) ELSE ( - goto %~1_local + SET PYTHON_EXE=python ) -:activate_interpreter_local -IF NOT EXIST %PROJECT%\.venv CALL %PROJECT_BIN%\install_py.bat -CALL %PROJECT%\.venv\Scripts\activate.bat -goto :eof +REM venv sicherstellen +IF NOT EXIST "%PROJECT%\.venv" ( + "%PYTHON_EXE%" -m venv "%PROJECT%\.venv" +) -:deactivate_interpreter_local -deactivate -goto :eof +REM venv aktivieren +CALL "%PROJECT%\.venv\Scripts\activate.bat" -:activate_interpreter_network -SET OLD_PATH=%PATH% -SET PATH=%NETWORK_INTERPRETER_PATH%;%PATH% -CALL %PROJECT%\.venv\Scripts\activate.bat -goto :eof +REM Interpreter festnageln +SET VIRTUAL_ENV_PYTHON=%PYTHON_EXE% +GOTO :eof -:deactivate_interpreter_network -SET PATH=%OLD_PATH% -SET OLD_PATH= -SET NETWORK_INTERPRETER_PATH= -CALL %PROJECT%\.venv\Scripts\deactivate.bat -goto :eof + +:deactivate +CALL "%PROJECT%\.venv\Scripts\deactivate.bat" +SET VIRTUAL_ENV_PYTHON= +GOTO :eof diff --git a/bin/portalexport.bat b/bin/portalexport.bat index 312441b..26d53b9 100644 --- a/bin/portalexport.bat +++ b/bin/portalexport.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\portalexport.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.portalexport %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/routing.bat b/bin/routing.bat index 6347351..9623a16 100644 --- a/bin/routing.bat +++ b/bin/routing.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\routing.py %* -CALL manage_interpreter.bat deactivate_interpreter +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.routing %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% diff --git a/bin/run_test.bat b/bin/run_test.bat index 6b0006d..87a42a4 100644 --- a/bin/run_test.bat +++ b/bin/run_test.bat @@ -65,12 +65,23 @@ echo Test-Parameter: %TEST_PARAMS% echo ============================================================================ echo. -REM Wechsle ins Projektverzeichnis und führe run_tests.py aus -cd /d "%PROJECT%" -python "%PROJECT_LIB%\run_tests.py" %TEST_PARAMS% +REM Python-Umgebung aktivieren +CALL "%PROJECT_BIN%\manage_interpreter.bat" activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) +REM Wechsle ins Projektverzeichnis und führe run_tests.py aus +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.run_tests %TEST_PARAMS% set TEST_RESULT=%ERRORLEVEL% +popd +REM Python-Umgebung deaktivieren +CALL "%PROJECT_BIN%\manage_interpreter.bat" deactivate + echo. echo ============================================================================ if %TEST_RESULT% EQU 0 ( diff --git a/bin/run_tests.bat b/bin/run_tests.bat index b9a9a69..a85237a 100644 --- a/bin/run_tests.bat +++ b/bin/run_tests.bat @@ -4,24 +4,28 @@ REM Calls run_tests.py to execute all tests call %~dp0setenv.bat -CALL manage_interpreter.bat activate_interpreter -if %ERRORLEVEL% NEQ 0 ( +CALL manage_interpreter.bat activate +if errorlevel 1 ( echo. echo Failed to activate the Python interpreter! pause exit /B 1 ) -python %PROJECT_LIB%\run_tests.py %* +pushd "%PROJECT%" -if %ERRORLEVEL% NEQ 0 ( +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.run_tests %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate + +if %PYTHON_EXIT% NEQ 0 ( echo. echo Tests failed! - CALL manage_interpreter.bat deactivate_interpreter exit /B 1 ) else ( echo. echo All tests passed! - CALL manage_interpreter.bat deactivate_interpreter exit /B 0 ) \ No newline at end of file diff --git a/bin/setenv.bat b/bin/setenv.bat index 5507701..6f2d428 100644 --- a/bin/setenv.bat +++ b/bin/setenv.bat @@ -2,7 +2,10 @@ REM falls Umlaute in den Pfaden sind: chcp 65001 > nul -set PROJECT=c:\kabellaengen +REM ~dp0 steht für das Verzeichnis, in der diese Datei liegt +pushd %~dp0\.. + +set PROJECT=%cd% set PROJECT_BIN=%PROJECT%\bin set PROJECT_CFG=%PROJECT%\cfg set PROJECT_DOC=%PROJECT%\doc @@ -32,6 +35,7 @@ if exist "%~dp0_setenv.bat" ( REM Prüfe ob PATH bereits erweitert wurde set PATH=%PROJECT_BIN%;%PATH% +REM set NETWORK_PYTHON=TO_BE_SET popd diff --git a/bin/setenv.sh b/bin/setenv.sh index 63fea69..755f53f 100755 --- a/bin/setenv.sh +++ b/bin/setenv.sh @@ -1,6 +1,8 @@ #!/bin/bash -export PROJECT=$HOME/dxf-calculator/kabellaengen +# Determine the project directory dynamically +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +export PROJECT="$(cd "$SCRIPT_DIR/.." && pwd)" export PROJECT_BIN="$PROJECT/bin" export PROJECT_CFG="$PROJECT/cfg" export PROJECT_DOC="$PROJECT/doc" @@ -8,6 +10,8 @@ export PROJECT_LIB="$PROJECT/lib" export PROJECT_DATA="$PROJECT/data" export PROJECT_WORK="$PROJECT/work" export PROJECT_TEST="$PROJECT/testdata" +export PROJECT_LOG="$PROJECT/logs" +export PROJECT_TRANSLATION="$PROJECT/translation" # Linux executable instead of Windows .exe export SIVAS_TEILESTAMM="/usr/local/bin/KSbExcelExportSivasTeilestamm" @@ -16,6 +20,9 @@ export SIVAS_EXCEL_EXPORT_DIR="$PROJECT_DATA" # Create directories if they don't exist mkdir -p "$PROJECT/work" mkdir -p "$PROJECT/data" +mkdir -p "$PROJECT/logs" +mkdir -p "$PROJECT/translation" +mkdir -p "$PROJECT/testdata" # Samba shares (adjust mount points as needed) export PROJECT_IO_RESULTS=$PROJECT_WORK @@ -24,3 +31,6 @@ export INSTALL_DIR="$HOME/kabeltool" # Add project bin to PATH (only if not already added) export PATH="$PROJECT_BIN:$PATH" + +# Network Python interpreter (optional) +# export NETWORK_PYTHON=/path/to/network/python diff --git a/bin/translate.bat b/bin/translate.bat index 578be49..7257a16 100644 --- a/bin/translate.bat +++ b/bin/translate.bat @@ -1,4 +1,15 @@ @echo off -CALL manage_interpreter.bat activate_interpreter -python %PROJECT_LIB%\translate.py %* -CALL manage_interpreter.bat deactivate_interpreter \ No newline at end of file +CALL manage_interpreter.bat activate +if errorlevel 1 ( + echo ERROR: Failed to activate Python environment + exit /b 1 +) + +pushd "%PROJECT%" + +"%VIRTUAL_ENV%\Scripts\python.exe" -m lib.translate %* +set PYTHON_EXIT=%ERRORLEVEL% + +popd +CALL manage_interpreter.bat deactivate +exit /b %PYTHON_EXIT% \ No newline at end of file diff --git a/cfg/create_tests.json b/cfg/create_tests.json index 358bf42..96d02b8 100644 --- a/cfg/create_tests.json +++ b/cfg/create_tests.json @@ -38,7 +38,7 @@ "layer_name": "ILS_MOTOR", "direction": "LEFT_RIGHT", "x": 800, - "y": 800, + "y": 900, "width": 4000, "height": 450, "use_polyline": false @@ -49,8 +49,8 @@ "kennzeichnung": "A01+UH00", "layer_name": "ILS_MOTOR", "direction": "LEFT_RIGHT", - "x": 450, - "y": 100, + "x": 400, + "y": 75, "width": 1400, "height": 480, "use_polyline": true @@ -159,6 +159,136 @@ ] } ] + }, + + "BG_Multi_Frames": { + "description": "Test-Szene mit drei Rechtecken für BG-1@@@ und BG-2@@@ Symbole mit mehreren Layern", + "ma_groups": [ + { + "name": "BG-1@@_frame1", + "count": 1, + "layout_type": "single", + "base_x": 700, + "base_y": 700, + "spacing": 0 + }, + { + "name": "BG-1@@_frame2_1", + "count": 1, + "layout_type": "single", + "base_x": 3500, + "base_y": 2350, + "spacing": 0 + }, + { + "name": "BG-1@@_frame2_2", + "count": 1, + "layout_type": "single", + "base_x": 4800, + "base_y": 2400, + "spacing": 0 + }, + { + "name": "BG-1@@_frame2_3", + "count": 1, + "layout_type": "single", + "base_x": 6100, + "base_y": 2300, + "spacing": 0 + }, + { + "name": "MB-1@@_frame2_1", + "count": 1, + "layout_type": "single", + "base_x": 3500, + "base_y": 2800, + "spacing": 0 + }, + { + "name": "MB-1@@_frame2_2", + "count": 1, + "layout_type": "single", + "base_x": 4800, + "base_y": 2850, + "spacing": 0 + }, + { + "name": "MB-1@@_frame2_3", + "count": 1, + "layout_type": "single", + "base_x": 6100, + "base_y": 2750, + "spacing": 0 + }, + { + "name": "BG-2@@_frame3_1", + "count": 1, + "layout_type": "single", + "base_x": 3700, + "base_y": 700, + "spacing": 0 + }, + { + "name": "BG-2@@_frame3_2", + "count": 1, + "layout_type": "single", + "base_x": 5000, + "base_y": 700, + "spacing": 0 + }, + { + "name": "BG-2@@_frame3_3", + "count": 1, + "layout_type": "single", + "base_x": 6300, + "base_y": 700, + "spacing": 0 + } + ], + "renaming_frames": [ + { + "comment": "Rahmen 1: Links unten - 1x BG-1@@@ (Polylinie)", + "name": "BG-1@@@", + "name2": "MB-1@@@", + "kennzeichnung": "", + "layer_name1": "ILS_Eingang", + "layer_name2": "ILS_Ausgang", + "direction": "LEFT_RIGHT", + "x": 300, + "y": 500, + "width": 1200, + "height": 500, + "use_polyline": true + }, + { + "comment": "Rahmen 2: Rechts oben - 3x BG-1@@@ + 3x MB-1@@@ (Polylinie)", + "name": "BG-1@@@", + "name2": "MB-1@@@", + "kennzeichnung": "", + "layer_name1": "ILS_Eingang", + "layer_name2": "ILS_Ausgang", + "direction": "LEFT_RIGHT", + "x": 3000, + "y": 2000, + "width": 3600, + "height": 1000, + "use_polyline": true + }, + { + "comment": "Rahmen 3: Rechts unten - 3x BG-2@@@ (normales Rechteck)", + "name": "BG-2@@@", + "name2": "MB-2@@@", + "kennzeichnung": "", + "layer_name1": "ILS_Eingang", + "layer_name2": "ILS_Ausgang", + "direction": "LEFT_RIGHT", + "x": 3200, + "y": 500, + "width": 3600, + "height": 500, + "use_polyline": false + } + ] } }, @@ -229,47 +359,47 @@ "_description": "ATTDEF Positionen im inneren Block RENAMER_ATTRIB_MULTI", "NAME1": { "x": 10, - "y": 80, + "y": -10, "height": 21.25 }, "NAME2": { "x": 10, - "y": 60, + "y": -45, "height": 21.25 }, "NAME3": { "x": 10, - "y": 40, + "y": -80, "height": 21.25 }, "KENNZEICHNUNG": { "x": 10, - "y": 20, + "y": -115, "height": 21.25 }, "LAYER_NAME1": { "x": 10, - "y": -20, + "y": -150, "height": 21.25 }, "LAYER_NAME2": { "x": 10, - "y": -40, + "y": -185, "height": 21.25 }, "LAYER_NAME3": { "x": 10, - "y": -60, + "y": -220, "height": 21.25 }, "DIRECTION": { "x": 10, - "y": -80, + "y": -255, "height": 21.25 }, "ID": { "x": 10, - "y": -100, + "y": -290, "height": 21.25 } } diff --git a/lib/create_example.py b/lib/create_example.py index 1727686..06a8d03 100644 --- a/lib/create_example.py +++ b/lib/create_example.py @@ -405,7 +405,8 @@ class TestDataGenerator: return attrib_block def create_renamer_frame(self, insert_point, width, height, name, kennzeichnung, - layer_name, direction, use_polyline=False, frame_type='MA'): + layer_name, direction, use_polyline=False, frame_type='MA', + name2='', name3='', layer_name2='', layer_name3='', id_value=''): """ Erstellt einen Renamer-Rahmen mit zweistufiger Block-Struktur auf Layer ILS_RENAMER @@ -475,9 +476,18 @@ class TestDataGenerator: 'LAYER_NAME': layer_name, 'DIRECTION': direction }) - else: # MULTI - würde später für BG/MG/POT verwendet - # Placeholder für Multi-Layer Frame - pass + else: # MULTI - für BG/MG/POT mit mehreren Layern + attrib_blockref.add_auto_attribs({ + 'NAME1': name, + 'NAME2': name2, + 'NAME3': name3, + 'KENNZEICHNUNG': kennzeichnung, + 'LAYER_NAME1': layer_name, + 'LAYER_NAME2': layer_name2, + 'LAYER_NAME3': layer_name3, + 'DIRECTION': direction, + 'ID': id_value + }) # Füge Block-Referenz im Modelspace ein blockref = self.msp.add_blockref( @@ -724,16 +734,39 @@ class TestDataGenerator: ) else: # Standard Rectangle Frame - self.create_renamer_frame( - insert_point=(frame_config['x'], frame_config['y']), - width=frame_config['width'], - height=frame_config['height'], - name=frame_config['name'], - kennzeichnung=frame_config['kennzeichnung'], - layer_name=frame_config['layer_name'], - direction=frame_config['direction'], - use_polyline=frame_config.get('use_polyline', False) - ) + # Prüfe ob es ein MULTI-Frame ist (NAME1/NAME2 statt NAME) + is_multi_frame = 'name2' in frame_config or 'layer_name1' in frame_config + + if is_multi_frame: + # MULTI-Frame (BG, MG, POT mit mehreren Layern) + self.create_renamer_frame( + insert_point=(frame_config['x'], frame_config['y']), + width=frame_config['width'], + height=frame_config['height'], + name=frame_config.get('name', ''), + kennzeichnung=frame_config.get('kennzeichnung', ''), + layer_name=frame_config.get('layer_name1', ''), + direction=frame_config.get('direction', ''), + use_polyline=frame_config.get('use_polyline', False), + frame_type='MULTI', + name2=frame_config.get('name2', ''), + name3=frame_config.get('name3', ''), + layer_name2=frame_config.get('layer_name2', ''), + layer_name3=frame_config.get('layer_name3', ''), + id_value=frame_config.get('id', '') + ) + else: + # MA-Frame (einfacher Frame) + self.create_renamer_frame( + insert_point=(frame_config['x'], frame_config['y']), + width=frame_config['width'], + height=frame_config['height'], + name=frame_config['name'], + kennzeichnung=frame_config['kennzeichnung'], + layer_name=frame_config['layer_name'], + direction=frame_config['direction'], + use_polyline=frame_config.get('use_polyline', False) + ) # Prüfe ob alle generierten Symbole in einem Renamer-Frame liegen self._validate_symbols_in_frames(scene)