mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-06-01 22:00:53 +00:00
pyCreateTh.py
This commit is contained in:
@@ -50,3 +50,16 @@
|
||||
2025-06-16 19:05:25,447 - INFO - ********************************************************************************************************************************************
|
||||
2025-06-16 19:05:25,448 - ERROR - !!! file not yet supported
|
||||
2025-06-16 19:05:25,448 - ERROR - !!! There were 1 errors during 13.29 secondes, check the log file ~\..\pyCreateTh.log
|
||||
2025-06-16 21:47:56,145 - INFO - ********************************************************************************************************************************************
|
||||
2025-06-16 21:47:56,149 - INFO - * Conversion Th, Dat, Mak files to Therion files and folders
|
||||
2025-06-16 21:47:56,150 - INFO - * Script pyCreateTh by : alexandre.pont@yahoo.fr
|
||||
2025-06-16 21:47:56,150 - INFO - * Version : 2025.06.16
|
||||
2025-06-16 21:47:56,150 - INFO - * Input file :
|
||||
2025-06-16 21:47:56,150 - INFO - * Output file : ~\.
|
||||
2025-06-16 21:47:56,151 - INFO - * Log file : ~\..\pyCreateTh.log
|
||||
2025-06-16 21:47:56,151 - INFO - *
|
||||
2025-06-16 21:47:56,151 - INFO - *
|
||||
2025-06-16 21:47:56,151 - INFO - *
|
||||
2025-06-16 21:47:56,152 - INFO - ********************************************************************************************************************************************
|
||||
2025-06-16 21:47:56,153 - ERROR - !!! file not yet supported
|
||||
2025-06-16 21:47:56,154 - ERROR - !!! There were 1 errors during 3.19 secondes, check the log file ~\..\pyCreateTh.log
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
## Global data for pyCreateTh.py
|
||||
|
||||
|
||||
# # [Survey_Data] default values
|
||||
# Author = "Created by pyCreateTh.py"
|
||||
# Copyright = "# Copyright (C) pyCreateTh.py"
|
||||
# Copyright_Short = "Licence (C) pyCreateTh.py"
|
||||
# map_comment = "Created by pyCreateTh.py"
|
||||
# cs = "UTM30"
|
||||
# club = "Therion"
|
||||
# thanksto = "Therion"
|
||||
# datat = "https://therion.speleo.sk/"
|
||||
# wpage = "https://therion.speleo.sk/"
|
||||
|
||||
# ## [Application_data] default values
|
||||
# template_path = "./Template"
|
||||
# station_by_scrap = 20
|
||||
# final_therion_exe = True
|
||||
# therion_path = "C:/Therion/therion.exe"
|
||||
# LINES = -1
|
||||
# NAMES = -1
|
||||
|
||||
# configIni = "config.ini" # Default config file name
|
||||
# debug_log = False # Mode debug des messages
|
||||
error_count = 0 # Compteur d'erreurs
|
||||
@@ -6,6 +6,7 @@ import subprocess
|
||||
import re
|
||||
import logging
|
||||
import threading
|
||||
import Lib.global_data as global_data
|
||||
|
||||
log = logging.getLogger("Logger")
|
||||
|
||||
@@ -47,7 +48,7 @@ def safe_relpath(path):
|
||||
return valeur
|
||||
|
||||
except ValueError:
|
||||
max_depth = 7
|
||||
max_depth = 6 # Profondeur maximale pour tronquer le chemin
|
||||
|
||||
# Disques différents, afficher le chemin relatif partiel depuis la racine commune
|
||||
path_parts = abs_path.split(os.sep)
|
||||
@@ -67,8 +68,9 @@ def safe_relpath(path):
|
||||
|
||||
|
||||
#################################################################################################
|
||||
def compile_template(template, template_args, **kwargs):
|
||||
global error_count
|
||||
# Compilation Therion 'Template' (version avec blocage) #
|
||||
#################################################################################################
|
||||
def compile_templateOld(template, template_args, **kwargs):
|
||||
|
||||
try :
|
||||
logfile = ""
|
||||
@@ -94,12 +96,13 @@ def compile_template(template, template_args, **kwargs):
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
||||
error_count += 1
|
||||
|
||||
global_data.error_count += 1
|
||||
|
||||
#################################################################################################
|
||||
def compile_template2(template, template_args, **kwargs):
|
||||
global error_count
|
||||
# Compilation Therion 'Template' (version sans blocage) #
|
||||
# Compiler une configuration générée dynamiquement à partir d'un template texte. #
|
||||
#################################################################################################
|
||||
def compile_template(template, template_args, **kwargs):
|
||||
|
||||
logfile = ""
|
||||
tmpdir = None
|
||||
@@ -125,7 +128,7 @@ def compile_template2(template, template_args, **kwargs):
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True, # Décode automatiquement en UTF-8 (avec fallback ci-dessous)
|
||||
timeout=kwargs.get("timeout", 60),
|
||||
timeout=kwargs.get("timeout", 30),
|
||||
errors="replace" # Remplace caractères invalides (évite UnicodeDecodeError)
|
||||
)
|
||||
|
||||
@@ -138,8 +141,8 @@ def compile_template2(template, template_args, **kwargs):
|
||||
|
||||
# Analyse du code retour
|
||||
if result.returncode != 0:
|
||||
log.error(f"Therion compilation failed with return code {Colors.ENDC}{result.returncode} {Colors.ERROR}{result.stdout}")
|
||||
error_count += 1
|
||||
log.error(f"Therion compilation failed with return code: {Colors.ENDC}{result.returncode} {Colors.ERROR}{result.stdout}")
|
||||
global_data.error_count += 1
|
||||
|
||||
else:
|
||||
log.info(f"Therion compilation successful")
|
||||
@@ -147,14 +150,14 @@ def compile_template2(template, template_args, **kwargs):
|
||||
return logfile, tmpdir
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
log.error(f"Therion process timed out and was terminated")
|
||||
error_count += 1
|
||||
return "Therion timeout", tmpdir
|
||||
log.error(f"Therion process timed out and was terminated {Colors.ENDC}{logfile}")
|
||||
global_data.error_count += 1
|
||||
return "Therion error", tmpdir
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
||||
error_count += 1
|
||||
return str(e), tmpdir
|
||||
global_data.error_count += 1
|
||||
return "Therion error", tmpdir
|
||||
|
||||
finally:
|
||||
if kwargs.get("cleanup", True) and tmpdir:
|
||||
@@ -165,8 +168,10 @@ def compile_template2(template, template_args, **kwargs):
|
||||
|
||||
|
||||
#################################################################################################
|
||||
def compile_file(filename, **kwargs):
|
||||
global error_count
|
||||
# Compilation Therion (version avec blocage) #
|
||||
# Compiler directement un fichier .th déjà existant avec Therion.
|
||||
#################################################################################################
|
||||
def compile_fileOld(filename, **kwargs):
|
||||
|
||||
try:
|
||||
tmpdir = os.path.dirname(filename)
|
||||
@@ -200,25 +205,26 @@ def compile_file(filename, **kwargs):
|
||||
if process.returncode != 0:
|
||||
# Affichage des erreurs et de la sortie standard
|
||||
log.error(f"Error during Therion compilation, stderr : \n{Colors.ENDC}{process.stderr.decode()}")
|
||||
error_count += 1
|
||||
global_data.error_count += 1
|
||||
|
||||
log.info(f"Therion file : {Colors.ENDC}{safe_relpath(filename)}{Colors.GREEN} succeeded")
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"Therion file {Colors.ENDC}{safe_relpath(filename, os.path.expanduser('~'))}{Colors.ERROR} compilation error: {Colors.ENDC}{e}")
|
||||
error_count += 1
|
||||
global_data.error_count += 1
|
||||
|
||||
|
||||
#################################################################################################
|
||||
def compile_file2(filename, **kwargs):
|
||||
global error_count
|
||||
# Compilation Therion (version sans blocage) #
|
||||
#################################################################################################
|
||||
def compile_file(filename, **kwargs):
|
||||
|
||||
tmpdir = os.path.dirname(filename)
|
||||
log_file = join(tmpdir, "therion.log").replace("\\", "/")
|
||||
therion_path = kwargs.get("therion_path", "therion")
|
||||
timeout = kwargs.get("timeout", 60) # seconds
|
||||
|
||||
log.info(f"Start therion compilation file : {Colors.WHITE}{filename}")
|
||||
log.info(f"Start therion compilation file: {Colors.ENDC}{safe_relpath(filename)}")
|
||||
|
||||
try:
|
||||
# Lancement du processus Therion
|
||||
@@ -254,7 +260,7 @@ def compile_file2(filename, **kwargs):
|
||||
output_thread.join(timeout)
|
||||
if output_thread.is_alive():
|
||||
log.error(f"Therion compilation timed out after {Colors.ENDC}{timeout}{Colors.ERROR} seconds. Killing process...")
|
||||
error_count += 1
|
||||
global_data.error_count += 1
|
||||
process.kill()
|
||||
output_thread.join()
|
||||
|
||||
@@ -263,14 +269,14 @@ def compile_file2(filename, **kwargs):
|
||||
# Vérification du code de retour
|
||||
if process.returncode != 0:
|
||||
log.error(f"Therion returned error code {Colors.ENDC}{process.returncode}")
|
||||
error_count += 1
|
||||
global_data.error_count += 1
|
||||
|
||||
else:
|
||||
log.info(f"Therion file : {Colors.ENDC}{safe_relpath(filename)}{Colors.GREEN} compilation succeeded")
|
||||
log.info(f"Therion file: {Colors.ENDC}{safe_relpath(filename)}{Colors.GREEN} compilation succeeded")
|
||||
|
||||
except Exception as e:
|
||||
log.error(f"Therion file {Colors.ENDC}{safe_relpath(filename)}{Colors.ERROR} compilation error: {Colors.ENDC}{e}")
|
||||
error_count += 1
|
||||
log.error(f"Therion file: {Colors.ENDC}{safe_relpath(filename)}{Colors.ERROR} compilation error: {Colors.ENDC}{e}")
|
||||
global_data.error_count += 1
|
||||
|
||||
|
||||
#################################################################################################
|
||||
|
||||
@@ -18,5 +18,5 @@ template_path = ./template
|
||||
station_by_scrap = 30
|
||||
final_therion_exe = True
|
||||
therion_path = C:\Program Files\Therion\therion.exe
|
||||
shot_lines_in_th2_files = False
|
||||
station_name_in_th2_files = False
|
||||
shot_lines_in_th2_files = True
|
||||
station_name_in_th2_files = True
|
||||
|
||||
+661
-650
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user