mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-07-31 16:35:00 +00:00
update pyCreateTh
This commit is contained in:
Binary file not shown.
@@ -10,6 +10,7 @@ Alex 2025 06 09
|
||||
import os, logging, sys, re, configparser, unicodedata, shutil
|
||||
from pathlib import Path
|
||||
import Lib.global_data as global_Data
|
||||
from datetime import datetime
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
@@ -218,7 +219,7 @@ def select_file_tk_window():
|
||||
|
||||
|
||||
#################################################################################################
|
||||
def load_config(args, configIni="config.ini"):
|
||||
def load_config_old(args, configIni="config.ini"):
|
||||
"""
|
||||
Charge un fichier de configuration .ini et initialise les variables globales.
|
||||
|
||||
@@ -288,6 +289,169 @@ def load_config(args, configIni="config.ini"):
|
||||
exit(0)
|
||||
|
||||
|
||||
def load_config(args, configIni="config.ini", profile="Default"):
|
||||
"""
|
||||
Charge un fichier de configuration .ini et initialise les variables globales.
|
||||
|
||||
Args:
|
||||
args: Argument contenant le chemin du fichier principal.
|
||||
configIni: Nom du fichier de configuration.
|
||||
profile: Nom du profil Survey_Data à utiliser.
|
||||
Exemple : Survey_Data:PSM
|
||||
"""
|
||||
try:
|
||||
|
||||
# Chemin potentiel du fichier config
|
||||
config_file = os.path.join(os.path.dirname(args.file), configIni)
|
||||
if not os.path.isfile(config_file):
|
||||
config_file = configIni
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_file, encoding="utf-8")
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Sélection du profil Survey_Data
|
||||
# ----------------------------------------------------------
|
||||
|
||||
survey_section = f"Survey_Data:{profile}"
|
||||
|
||||
if survey_section in config:
|
||||
survey_cfg = config[survey_section]
|
||||
|
||||
elif "Survey_Data" in config:
|
||||
# Compatibilité ancienne configuration
|
||||
survey_cfg = config["Survey_Data"]
|
||||
|
||||
if profile != "Default":
|
||||
log.warning(f"Profile '{Colors.ENDC}{profile}{Colors.WARNING}' not found. Using legacy default {Colors.ENDC}[Survey_Data]{Colors.WARNING} section.")
|
||||
profile = "Default"
|
||||
else:
|
||||
raise ValueError(f"Section [{survey_section}] not found and no legacy [Survey_Data] section available.")
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Lecture Survey_Data
|
||||
# ----------------------------------------------------------
|
||||
|
||||
survey_keys = {
|
||||
'Author': 'Author',
|
||||
'Copyright1': 'Copyright',
|
||||
'Copyright2': 'Copyright',
|
||||
'Copyright3': 'Copyright',
|
||||
'Copyright_Short': None,
|
||||
'map_comment': 'mapComment',
|
||||
'club': 'club',
|
||||
'thanksto': 'thanksto',
|
||||
'datat': 'datat',
|
||||
'wpage': 'wpage',
|
||||
'cs': 'cs'
|
||||
}
|
||||
|
||||
# ==========================================================
|
||||
# Variables de substitution
|
||||
# ==========================================================
|
||||
|
||||
variables = {
|
||||
"YEAR": str(datetime.now().year)
|
||||
}
|
||||
|
||||
def expand(value):
|
||||
try:
|
||||
return value.format(**variables)
|
||||
except Exception:
|
||||
return value
|
||||
|
||||
# ==========================================================
|
||||
# Lecture Survey_Data
|
||||
# ==========================================================
|
||||
|
||||
survey_keys = {
|
||||
'Author': 'Author',
|
||||
'map_comment': 'mapComment',
|
||||
'club': 'club',
|
||||
'thanksto': 'thanksto',
|
||||
'datat': 'datat',
|
||||
'wpage': 'wpage',
|
||||
'cs': 'cs'
|
||||
}
|
||||
|
||||
for key, attr in survey_keys.items():
|
||||
|
||||
if key in survey_cfg:
|
||||
|
||||
value = expand(survey_cfg[key])
|
||||
|
||||
setattr(global_Data, attr, value)
|
||||
|
||||
# ==========================================================
|
||||
# Gestion Copyright
|
||||
# ==========================================================
|
||||
|
||||
copyright_lines = []
|
||||
|
||||
for key in ("Copyright1", "Copyright2", "Copyright3"):
|
||||
|
||||
if key in survey_cfg:
|
||||
|
||||
copyright_lines.append(
|
||||
expand(survey_cfg[key])
|
||||
)
|
||||
|
||||
if copyright_lines:
|
||||
|
||||
global_Data.Copyright = "\n".join(
|
||||
copyright_lines
|
||||
)
|
||||
|
||||
if "Copyright_Short" in survey_cfg:
|
||||
|
||||
global_Data.CopyrightShort = expand(
|
||||
survey_cfg["Copyright_Short"]
|
||||
)
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Lecture Application_Data
|
||||
# ----------------------------------------------------------
|
||||
|
||||
app_keys = {
|
||||
'template_path': 'templatePath',
|
||||
'station_by_scrap': ('stationByScrap', int),
|
||||
'final_therion_exe': ('finalTherionExe', lambda x: x.lower() == 'true'),
|
||||
'parse_tro_files_by_explo': ('parse_tro_files_by_explo', lambda x: x.lower() == 'true'),
|
||||
'therion_path': 'therionPath',
|
||||
'survey_prefix_name': 'SurveyPrefixName',
|
||||
'shot_lines_in_th2_files': ('linesInTh2', lambda x: x.lower() == 'true'),
|
||||
'station_name_in_th2_files': ('stationNamesInTh2', lambda x: x.lower() == 'true'),
|
||||
'wall_lines_in_th2_files': ('wallLinesInTh2', lambda x: x.lower() == 'true'),
|
||||
'kSmooth': ('kSmooth', float)
|
||||
}
|
||||
|
||||
if 'Application_Data' in config:
|
||||
|
||||
for key, value in app_keys.items():
|
||||
if key not in config['Application_Data']:
|
||||
continue
|
||||
|
||||
attr, caster = (
|
||||
(value, str)
|
||||
if isinstance(value, str)
|
||||
else value
|
||||
)
|
||||
|
||||
setattr(
|
||||
global_Data,
|
||||
attr,
|
||||
caster(config['Application_Data'][key])
|
||||
)
|
||||
|
||||
# log.info(f"Configuration profile : {profile}")
|
||||
|
||||
return config_file, profile
|
||||
|
||||
except Exception as e:
|
||||
log.critical(f"Reading config file : {Colors.ENDC}{configIni}{Colors.ERROR} error : {Colors.ENDC}{e}" )
|
||||
exit(0)
|
||||
|
||||
#################################################################################################
|
||||
# Supprime les codes ANSI (pour l'écriture dans les fichiers)
|
||||
#################################################################################################
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#############################################################################################
|
||||
# config.ini file for configuration values of pyCreateTh.py script
|
||||
#############################################################################################
|
||||
|
||||
#############################################################################################
|
||||
# General layout information :
|
||||
[Survey_Data]
|
||||
#############################################################################################
|
||||
[Survey_Data] # Default
|
||||
Author = Alexandre Pont
|
||||
Copyright1 = # Copyright (C) ARSIP 2026
|
||||
Copyright1 = # Copyright (C) ARSIP {YEAR}
|
||||
Copyright2 = # This work is under the Creative Commons Attribution-NonCommercial-NoDerivatives License:
|
||||
Copyright3 = # <http://creativecommons.org/licenses/by-nc-nd/4.0/>
|
||||
Copyright_Short = License CC by-nc-nd : http://creativecommons.org/licenses/by-nc-nd/4.0/
|
||||
@@ -14,8 +18,48 @@ datat = https://github.com/Alex38Lyon/Synthese-PSM_LARRA
|
||||
wpage = https://www.arsip.fr/
|
||||
cs = UTM30
|
||||
|
||||
[Survey_Data:Tritons]
|
||||
Author = Alexandre Pont
|
||||
Copyright1 = # Copyright (C) Clan des Tritons {YEAR}
|
||||
Copyright2 = # This work is under the Creative Commons Attribution-NonCommercial-NoDerivatives License:
|
||||
Copyright3 = # <http://creativecommons.org/licenses/by-nc-nd/4.0/>
|
||||
Copyright_Short = License CC by-nc-nd : http://creativecommons.org/licenses/by-nc-nd/4.0/
|
||||
map_comment = Massif XXXX
|
||||
club = Clan des Tritons
|
||||
thanksto = Merci à tout le monde
|
||||
datat = https://github.com/Alex38Lyon/Topographies-Diverses_Tritons
|
||||
wpage = https://clandestritons.fr/
|
||||
cs = UTM30
|
||||
|
||||
# configuration data
|
||||
[Survey_Data:PSM]
|
||||
Author = Alexandre Pont
|
||||
Copyright1 = # Copyright (C) ARSIP {YEAR}
|
||||
Copyright2 = # This work is under the Creative Commons Attribution-NonCommercial-NoDerivatives License:
|
||||
Copyright3 = # <http://creativecommons.org/licenses/by-nc-nd/4.0/>
|
||||
Copyright_Short = License CC by-nc-nd : http://creativecommons.org/licenses/by-nc-nd/4.0/
|
||||
map_comment = Massif de la Pierre Saint Martin - Larra
|
||||
club = ARSIP
|
||||
thanksto = Merci à tout le monde
|
||||
datat = https://github.com/Alex38Lyon/Synthese-PSM_LARRA
|
||||
wpage = https://www.arsip.fr/
|
||||
cs = UTM30
|
||||
|
||||
[Survey_Data:Xichou]
|
||||
Author = Alexandre Pont
|
||||
Copyright1 = # Copyright (C) XIchou {YEAR}
|
||||
Copyright2 = # This work is under the Creative Commons Attribution-NonCommercial-NoDerivatives License:
|
||||
Copyright3 = # <http://creativecommons.org/licenses/by-nc-nd/4.0/>
|
||||
Copyright_Short = License CC by-nc-nd : http://creativecommons.org/licenses/by-nc-nd/4.0/
|
||||
map_comment = Xichou {YEAR}
|
||||
club = Xichou
|
||||
thanksto = Merci à tout le monde
|
||||
datat =
|
||||
wpage =
|
||||
cs = UTM48
|
||||
|
||||
#############################################################################################
|
||||
# Configuration data
|
||||
#############################################################################################
|
||||
[Application_Data]
|
||||
template_path = ./template
|
||||
station_by_scrap = 30
|
||||
|
||||
@@ -28,6 +28,7 @@ Sources documentaires :
|
||||
|
||||
|
||||
Création Alex le 2025 06 09
|
||||
Mise à jour : 2026 06 20
|
||||
|
||||
En cours :
|
||||
- Exports Tro :
|
||||
@@ -38,8 +39,8 @@ En cours :
|
||||
- A créer pour avoir notamment les réseaux à plusieurs entrées
|
||||
- Exports DAT/MARK
|
||||
- Attention les Flags '#|L#' posent problèmes (A voir convertisseur PdB vers compass...)
|
||||
- tester avec les dernières option de la version de DAT (CORRECTION2 et suivants)
|
||||
- améliorer fonction wall shot pour faire habillage des th2 files, les jointures...
|
||||
- Tester avec les dernières option de la version de DAT (CORRECTION2 et suivants)
|
||||
- Améliorer fonction wall shot pour faire habillage des th2 files, les jointures...
|
||||
- traiter les series avec 1 ou 2 stations
|
||||
- PB des cartouches et des échelles pour faire des pdf automatiquement
|
||||
|
||||
@@ -2191,6 +2192,7 @@ if __name__ == u'__main__':
|
||||
threads = []
|
||||
fileTitle = ""
|
||||
_fileTitle = ""
|
||||
profile = "Default"
|
||||
|
||||
#################################################################################################
|
||||
# Parse arguments #
|
||||
@@ -2202,16 +2204,26 @@ if __name__ == u'__main__':
|
||||
parser.add_argument("--file", help="the file (*.th, *.mak, *.dat, *.tro) to perform e.g. './Therion_file.th'", default="")
|
||||
parser.add_argument("--proj", choices=['All', 'Plan', 'Extended', 'None'], help="the th2 files scrap projection to produce, default: All", default="All")
|
||||
parser.add_argument("--scale", help="scale for the pdf layout exports, default value: 1000 (i.e. xvi files scale is 100)", default="1000")
|
||||
parser.add_argument("--update", help="th2 files update mode (only for th input files, no folders created)", action="store_true", default=False)
|
||||
parser.add_argument("--update", help=f"th2 files update mode (only for th input files, no folders created), {Colors.RED}Attention : save your old th2 files", action="store_true", default=False)
|
||||
|
||||
parser.epilog = (
|
||||
f"{Colors.GREEN}Please, complete {Colors.BLUE}config.ini{Colors.GREEN} in {Colors.BLUE}FILE{Colors.GREEN} folder or in script folder for personal configuration{Colors.ENDC}\n"
|
||||
f"{Colors.GREEN}If no argument: {Colors.BLUE} files selection by a windows\n{Colors.ENDC}\n"
|
||||
f"{Colors.BLUE}Examples:{Colors.ENDC}\n"
|
||||
f"\t> python pyCreateTh.py ./Tests/Entree.th --scale 1000\n"
|
||||
f"\t> python pyCreateTh.py Entree.th\n"
|
||||
f"{Colors.GREEN}Configuration profiles in {Colors.BLUE}config.ini{Colors.GREEN} file{Colors.ENDC}\n"
|
||||
f"{Colors.GREEN}\t{Colors.BLUE}--Default{Colors.ENDC}\tDefault configuration (or none){Colors.ENDC}\n"
|
||||
f"{Colors.GREEN}\t{Colors.BLUE}--PSM{Colors.ENDC}\t\tPSM configuration values{Colors.ENDC}\n\n"
|
||||
f"{Colors.GREEN}If no {Colors.BLUE}--file {Colors.GREEN}argument : {Colors.ENDC}files selection by a windows\n\n"
|
||||
f"{Colors.GREEN}Examples:{Colors.ENDC}\n"
|
||||
f"\t> python pyCreateTh.py ./Tests/Entree.th --scale 1000 --Default\n"
|
||||
f"\t> python pyCreateTh.py Entree.th --PSM\n"
|
||||
f"\t> python pyCreateTh.py --Tritons\n"
|
||||
f"\t> python pyCreateTh.py\n\n")
|
||||
args = parser.parse_args()
|
||||
args, unknown = parser.parse_known_args()
|
||||
|
||||
for arg in unknown:
|
||||
if arg.startswith("--"):
|
||||
profile = arg[2:]
|
||||
section = f"Survey_Data:{profile}"
|
||||
|
||||
|
||||
if args.file == "":
|
||||
args.file = select_file_tk_window()
|
||||
@@ -2233,7 +2245,7 @@ if __name__ == u'__main__':
|
||||
#################################################################################################
|
||||
# Reading config.ini #
|
||||
#################################################################################################
|
||||
config_file = load_config(args)
|
||||
config_file, profile = load_config(args, profile=profile)
|
||||
|
||||
#################################################################################################
|
||||
# titre #
|
||||
@@ -2262,7 +2274,7 @@ if __name__ == u'__main__':
|
||||
pad_line(f"Input file : {Colors.ENDC}{safe_relpath(args.file)}"),
|
||||
pad_line(f"Output folder : {Colors.ENDC}{safe_relpath(splitext(abspath(args.file))[0])}"),
|
||||
pad_line(f"Log file : {Colors.ENDC}{os.path.basename(output_log)}"),
|
||||
pad_line(f"Config file: {Colors.ENDC}{safe_relpath(config_file)}"),
|
||||
pad_line(f"Config file : {Colors.ENDC}{safe_relpath(config_file)}{Colors.GREEN}, profile : {Colors.ENDC}{profile}"),
|
||||
pad_line(""),
|
||||
bordure
|
||||
]
|
||||
@@ -2274,7 +2286,16 @@ if __name__ == u'__main__':
|
||||
if args.file == "":
|
||||
log.critical(f"No valid file selected, try again")
|
||||
exit(0)
|
||||
|
||||
|
||||
# print(f"{Colors.BLUE}Author = {Colors.ENDC}{globalData.Author}")
|
||||
# print(f"{Colors.BLUE}Copyright = {Colors.ENDC}{globalData.Copyright}")
|
||||
# print(f"{Colors.BLUE}CopyrightShort = {Colors.ENDC}{globalData.CopyrightShort}")
|
||||
# print(f"{Colors.BLUE}mapComment = {Colors.ENDC}{globalData.mapComment}")
|
||||
# print(f"{Colors.BLUE}cs = {Colors.ENDC}{globalData.cs}")
|
||||
# print(f"{Colors.BLUE}club = {Colors.ENDC}{globalData.club}")
|
||||
# print(f"{Colors.BLUE}thanksto = {Colors.ENDC}{globalData.thanksto}")
|
||||
# print(f"{Colors.BLUE}datat = {Colors.ENDC}{globalData.datat}")
|
||||
# print(f"{Colors.BLUE}wpage = {Colors.ENDC}{globalData.wpage}")
|
||||
|
||||
#################################################################################################
|
||||
# Fichier TH #
|
||||
|
||||
Reference in New Issue
Block a user