mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-06-01 13:59:13 +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,447 - INFO - ********************************************************************************************************************************************
|
||||||
2025-06-16 19:05:25,448 - ERROR - !!! file not yet supported
|
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 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 re
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
import Lib.global_data as global_data
|
||||||
|
|
||||||
log = logging.getLogger("Logger")
|
log = logging.getLogger("Logger")
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ def safe_relpath(path):
|
|||||||
return valeur
|
return valeur
|
||||||
|
|
||||||
except ValueError:
|
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
|
# Disques différents, afficher le chemin relatif partiel depuis la racine commune
|
||||||
path_parts = abs_path.split(os.sep)
|
path_parts = abs_path.split(os.sep)
|
||||||
@@ -64,11 +65,12 @@ def safe_relpath(path):
|
|||||||
result = os.path.join("~\\" , *parts[-max_depth:])
|
result = os.path.join("~\\" , *parts[-max_depth:])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
# Compilation Therion 'Template' (version avec blocage) #
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
def compile_template(template, template_args, **kwargs):
|
def compile_templateOld(template, template_args, **kwargs):
|
||||||
global error_count
|
|
||||||
|
|
||||||
try :
|
try :
|
||||||
logfile = ""
|
logfile = ""
|
||||||
@@ -94,13 +96,14 @@ def compile_template(template, template_args, **kwargs):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
# Compilation Therion 'Template' (version sans blocage) #
|
||||||
|
# Compiler une configuration générée dynamiquement à partir d'un template texte. #
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
def compile_template2(template, template_args, **kwargs):
|
def compile_template(template, template_args, **kwargs):
|
||||||
global error_count
|
|
||||||
|
|
||||||
logfile = ""
|
logfile = ""
|
||||||
tmpdir = None
|
tmpdir = None
|
||||||
try:
|
try:
|
||||||
@@ -125,7 +128,7 @@ def compile_template2(template, template_args, **kwargs):
|
|||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True, # Décode automatiquement en UTF-8 (avec fallback ci-dessous)
|
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)
|
errors="replace" # Remplace caractères invalides (évite UnicodeDecodeError)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,8 +141,8 @@ def compile_template2(template, template_args, **kwargs):
|
|||||||
|
|
||||||
# Analyse du code retour
|
# Analyse du code retour
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
log.error(f"Therion compilation failed with return code {Colors.ENDC}{result.returncode} {Colors.ERROR}{result.stdout}")
|
log.error(f"Therion compilation failed with return code: {Colors.ENDC}{result.returncode} {Colors.ERROR}{result.stdout}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info(f"Therion compilation successful")
|
log.info(f"Therion compilation successful")
|
||||||
@@ -147,14 +150,14 @@ def compile_template2(template, template_args, **kwargs):
|
|||||||
return logfile, tmpdir
|
return logfile, tmpdir
|
||||||
|
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
log.error(f"Therion process timed out and was terminated")
|
log.error(f"Therion process timed out and was terminated {Colors.ENDC}{logfile}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
return "Therion timeout", tmpdir
|
return "Therion error", tmpdir
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
log.error(f"Therion template compilation error: {Colors.ENDC}{e}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
return str(e), tmpdir
|
return "Therion error", tmpdir
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if kwargs.get("cleanup", True) and tmpdir:
|
if kwargs.get("cleanup", True) and tmpdir:
|
||||||
@@ -164,9 +167,11 @@ def compile_template2(template, template_args, **kwargs):
|
|||||||
log.warning(f"Could not delete temp directory: {Colors.ENDC}{cleanup_err}")
|
log.warning(f"Could not delete temp directory: {Colors.ENDC}{cleanup_err}")
|
||||||
|
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
# Compilation Therion (version avec blocage) #
|
||||||
|
# Compiler directement un fichier .th déjà existant avec Therion.
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
def compile_file(filename, **kwargs):
|
def compile_fileOld(filename, **kwargs):
|
||||||
global error_count
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tmpdir = os.path.dirname(filename)
|
tmpdir = os.path.dirname(filename)
|
||||||
@@ -200,25 +205,26 @@ def compile_file(filename, **kwargs):
|
|||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
# Affichage des erreurs et de la sortie standard
|
# Affichage des erreurs et de la sortie standard
|
||||||
log.error(f"Error during Therion compilation, stderr : \n{Colors.ENDC}{process.stderr.decode()}")
|
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")
|
log.info(f"Therion file : {Colors.ENDC}{safe_relpath(filename)}{Colors.GREEN} succeeded")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Therion file {Colors.ENDC}{safe_relpath(filename, os.path.expanduser('~'))}{Colors.ERROR} compilation error: {Colors.ENDC}{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
|
||||||
|
|
||||||
|
|
||||||
|
#################################################################################################
|
||||||
|
# Compilation Therion (version sans blocage) #
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
def compile_file2(filename, **kwargs):
|
def compile_file(filename, **kwargs):
|
||||||
global error_count
|
|
||||||
|
|
||||||
tmpdir = os.path.dirname(filename)
|
tmpdir = os.path.dirname(filename)
|
||||||
log_file = join(tmpdir, "therion.log").replace("\\", "/")
|
log_file = join(tmpdir, "therion.log").replace("\\", "/")
|
||||||
therion_path = kwargs.get("therion_path", "therion")
|
therion_path = kwargs.get("therion_path", "therion")
|
||||||
timeout = kwargs.get("timeout", 60) # seconds
|
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:
|
try:
|
||||||
# Lancement du processus Therion
|
# Lancement du processus Therion
|
||||||
@@ -254,7 +260,7 @@ def compile_file2(filename, **kwargs):
|
|||||||
output_thread.join(timeout)
|
output_thread.join(timeout)
|
||||||
if output_thread.is_alive():
|
if output_thread.is_alive():
|
||||||
log.error(f"Therion compilation timed out after {Colors.ENDC}{timeout}{Colors.ERROR} seconds. Killing process...")
|
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()
|
process.kill()
|
||||||
output_thread.join()
|
output_thread.join()
|
||||||
|
|
||||||
@@ -263,14 +269,14 @@ def compile_file2(filename, **kwargs):
|
|||||||
# Vérification du code de retour
|
# Vérification du code de retour
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
log.error(f"Therion returned error code {Colors.ENDC}{process.returncode}")
|
log.error(f"Therion returned error code {Colors.ENDC}{process.returncode}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
|
|
||||||
else:
|
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:
|
except Exception as e:
|
||||||
log.error(f"Therion file {Colors.ENDC}{safe_relpath(filename)}{Colors.ERROR} compilation error: {Colors.ENDC}{e}")
|
log.error(f"Therion file: {Colors.ENDC}{safe_relpath(filename)}{Colors.ERROR} compilation error: {Colors.ENDC}{e}")
|
||||||
error_count += 1
|
global_data.error_count += 1
|
||||||
|
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ template_path = ./template
|
|||||||
station_by_scrap = 30
|
station_by_scrap = 30
|
||||||
final_therion_exe = True
|
final_therion_exe = True
|
||||||
therion_path = C:\Program Files\Therion\therion.exe
|
therion_path = C:\Program Files\Therion\therion.exe
|
||||||
shot_lines_in_th2_files = False
|
shot_lines_in_th2_files = True
|
||||||
station_name_in_th2_files = False
|
station_name_in_th2_files = True
|
||||||
|
|||||||
+671
-660
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user