Mise à jour scripts

This commit is contained in:
Alex38Lyon
2025-03-25 16:00:22 +01:00
parent 8cb4dcfdc2
commit db0da00780
2 changed files with 161 additions and 79 deletions
+22
View File
@@ -0,0 +1,22 @@
# Configuration values for pyCreate_th2.ph
[Survey_Data]
Author = Alexandre Pont
Copyright1 = # Copyright (C) BK25 VV25 2025
Copyright2 = # This work is under the Creative Commons Attribution-NonCommercial-NoDerivatives License:
Copyright3 = # <http://creativecommons.org/licenses/by-nc-nd/4.0/>
Copyright_Short = Licence CC by-nc-nd : http://creativecommons.org/licenses/by-nc-nd/4.0/
map_comment = Laos - districk Vang Vieng
club = VV25 - S.C.A.
thanksto = Merçi à tout le monde
datat = https://www.explo-laos.fr/
wpage = https://www.explo-laos.fr/
cs = UTM48
[Application_Data]
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
+130 -70
View File
@@ -15,14 +15,17 @@
# # # #
############################################################################################# #############################################################################################
Creation Alex the 2024 12 16 : Création Alex the 2024 12 16 :
Thank's too Thank's too
- Tanguy Racine for the script https://github.com/tr1813 - Tanguy Racine for the script https://github.com/tr1813
- Xavier Robert for the main principes https://github.com/robertxa - Xavier Robert for the main principes https://github.com/robertxa
- Benoit Urruty https://github.com/BenoitURRUTY - Benoit Urruty https://github.com/BenoitURRUTY
Version 2025 03 21 : Création mode --update th2
""" """
Version ="2025.01.02" Version ="2025.03.21"
################################################################################################# #################################################################################################
################################################################################################# #################################################################################################
@@ -61,7 +64,7 @@ wpage = "https://therion.speleo.sk/"
template_path = "./template" template_path = "./template"
station_by_scrap = 20 station_by_scrap = 20
final_therion_exe = True final_therion_exe = True
therion_path = "C:\Therion\therion.exe" therion_path = "C:/Therion/therion.exe"
LINES = -1 LINES = -1
NAMES = -1 NAMES = -1
@@ -365,10 +368,13 @@ def select_file():
################################################################################################# #################################################################################################
# main function #
################################################################################################# #################################################################################################
if __name__ == u'__main__': if __name__ == u'__main__':
# Parse arguments #################################################################################################
# Parse arguments #
#################################################################################################
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=f"{Colors.HEADER}Create a skeleton folder and th2 files with scraps from a .th Therion file\nVersion: {Colors.ENDC}{Version}\n", description=f"{Colors.HEADER}Create a skeleton folder and th2 files with scraps from a .th Therion file\nVersion: {Colors.ENDC}{Version}\n",
formatter_class=argparse.RawDescriptionHelpFormatter) formatter_class=argparse.RawDescriptionHelpFormatter)
@@ -382,6 +388,7 @@ if __name__ == u'__main__':
parser.add_argument("--scale", help="Scale for the exports", default="500") parser.add_argument("--scale", help="Scale for the exports", default="500")
parser.add_argument("--lines", type=str_to_bool, help="Shot lines in th2 files", default=-1) parser.add_argument("--lines", type=str_to_bool, help="Shot lines in th2 files", default=-1)
parser.add_argument("--names", type=str_to_bool, help="Stations names in th2 files", default=-1) parser.add_argument("--names", type=str_to_bool, help="Stations names in th2 files", default=-1)
parser.add_argument("--update", help="Mode update, option th2", default="")
parser.epilog = ( parser.epilog = (
f"{Colors.GREEN}Please, complete {Colors.RED}config.ini{Colors.GREEN} file for personal configuration{Colors.ENDC}\n" f"{Colors.GREEN}Please, complete {Colors.RED}config.ini{Colors.GREEN} file for personal configuration{Colors.ENDC}\n"
@@ -392,11 +399,12 @@ if __name__ == u'__main__':
f"\t> python pyCreate_th2.py\n\n") f"\t> python pyCreate_th2.py\n\n")
args = parser.parse_args() args = parser.parse_args()
print("args.survey_file : " + args.survey_file ) # print("args.survey_file : " + args.survey_file )
# print("args.update : " + args.update )
if args.survey_file == "": if args.survey_file == "":
args.survey_file = select_file() args.survey_file = select_file()
print(f"Fichier sélectionné : {args.survey_file}") print(f"Selected file : {args.survey_file}")
ENTRY_FILE = abspath(args.survey_file) ENTRY_FILE = abspath(args.survey_file)
# PROJECTION = args.proj.capitalize() # PROJECTION = args.proj.capitalize()
@@ -426,6 +434,9 @@ if __name__ == u'__main__':
# print("DEST_PATH: " + DEST_PATH ) # print("DEST_PATH: " + DEST_PATH )
# print("ABS_PATH: " + ABS_PATH ) # print("ABS_PATH: " + ABS_PATH )
#################################################################################################
# Reading config.ini #
#################################################################################################
try: try:
# Load the 'database' section from the configuration file # Load the 'database' section from the configuration file
read_config("config.ini") read_config("config.ini")
@@ -472,39 +483,59 @@ if __name__ == u'__main__':
raise NoSurveysFoundException(f"{Colors.ERROR}Error: No survey found with that selector{Colors.ENDC}") raise NoSurveysFoundException(f"{Colors.ERROR}Error: No survey found with that selector{Colors.ENDC}")
if args.update == "th2":
print(f"{Colors.GREEN} Update th2 files {Colors.ENDC}")
print(f"\t{Colors.BLUE}survey_file : {Colors.ENDC} {args.survey_file}")
print(f"\t{Colors.BLUE}ENTRY_FILE: {Colors.ENDC} {ENTRY_FILE}")
print(f"\t{Colors.BLUE}PROJECTION: {Colors.ENDC} {PROJECTION}")
print(f"\t{Colors.BLUE}TARGET: {Colors.ENDC} {TARGET}")
print(f"\t{Colors.BLUE}OUTPUT: {Colors.ENDC} {OUTPUT}")
print(f"\t{Colors.BLUE}FORMAT: {Colors.ENDC} {FORMAT}")
print(f"\t{Colors.BLUE}SCALE: {Colors.ENDC} {SCALE}")
print(f"\t{Colors.BLUE}TH_NAME: {Colors.ENDC} {TH_NAME}")
DEST_PATH = os.path.dirname(args.survey_file)
print(f"\t{Colors.BLUE}DEST_PATH: {Colors.ENDC} {DEST_PATH}")
print(f"\t{Colors.BLUE}ABS_PATH: {Colors.ENDC} {ABS_PATH}")
################################################################################################# #################################################################################################
# Copy template folders # Copy template folders #
# print(f"{Colors.GREEN}Copy template folder and adapte it{Colors.ENDC}") #################################################################################################
copy_template_if_not_exists(template_path, DEST_PATH)
copy_file_with_copyright(ENTRY_FILE, DEST_PATH + "/Data", Copyright)
# Adapte templates if args.update == "":
config_vars = { # print(f"{Colors.GREEN}Copy template folder and adapte it{Colors.ENDC}")
'fileName': TH_NAME, copy_template_if_not_exists(template_path, DEST_PATH)
'cavename': TH_NAME.replace("_", " "), copy_file_with_copyright(ENTRY_FILE, DEST_PATH + "/Data", Copyright)
'Author': Author,
'Copyright': Copyright, # Adapte templates
'Scale' : SCALE, config_vars = {
'Target' : TARGET, 'fileName': TH_NAME,
'map_comment' : map_comment, 'cavename': TH_NAME.replace("_", " "),
'club' : club, 'Author': Author,
'thanksto' : thanksto.replace("_", r"\_"), 'Copyright': Copyright,
'datat' : datat.replace("_", r"\_"), 'Scale' : SCALE,
'wpage' : wpage.replace("_", r"\_"), 'Target' : TARGET,
'cs' : cs, 'map_comment' : map_comment,
'other_scraps_plan' : "", 'club' : club,
'file_info' : f'# File generated by pyCreate_th2.py (version {Version}) date: {datetime.now().strftime("%Y.%m.%d %H:%M:%S")}', 'thanksto' : thanksto.replace("_", r"\_"),
} 'datat' : datat.replace("_", r"\_"),
'wpage' : wpage.replace("_", r"\_"),
'cs' : cs,
'other_scraps_plan' : "",
'file_info' : f'# File generated by pyCreate_th2.py (version {Version}) date: {datetime.now().strftime("%Y.%m.%d %H:%M:%S")}',
}
process_template(DEST_PATH + '/template.thconfig', config_vars, DEST_PATH + '/' + TH_NAME + '.thconfig')
process_template(DEST_PATH + '/template-tot.th', config_vars, DEST_PATH + '/' + TH_NAME + '-tot.th')
process_template(DEST_PATH + '/template-readme.md', config_vars, DEST_PATH + '/readme.md')
process_template(DEST_PATH + '/template.thconfig', config_vars, DEST_PATH + '/' + TH_NAME + '.thconfig')
process_template(DEST_PATH + '/template-tot.th', config_vars, DEST_PATH + '/' + TH_NAME + '-tot.th')
process_template(DEST_PATH + '/template-readme.md', config_vars, DEST_PATH + '/readme.md')
################################################################################################# #################################################################################################
# Produce the parsable XVI file # Produce the parsable XVI file #
#################################################################################################
print(f"{Colors.GREEN}Compiling 2D XVI file: \t{Colors.ENDC} {TH_NAME}") print(f"{Colors.GREEN}Compiling 2D XVI file: \t{Colors.ENDC} {TH_NAME}")
template = """source "{th_file}" template = """source "{th_file}"
@@ -519,20 +550,33 @@ if __name__ == u'__main__':
export map -projection extended -o "{th_name}-Extended.xvi" -layout minimal -layout-debug station-names export map -projection extended -o "{th_name}-Extended.xvi" -layout minimal -layout-debug station-names
""" """
template_args = { if args.update == "th2":
"th_file": DEST_PATH + "/Data/" + TH_NAME + ".th", template_args = {
"selector": survey.therion_id, "th_file": DEST_PATH + "/" + TH_NAME + ".th",
"th_name": DEST_PATH + "/Data/" + TH_NAME, "selector": survey.therion_id,
"scale": SCALE, "th_name": DEST_PATH + "/" + TH_NAME,
} "scale": SCALE,
}
else :
template_args = {
"th_file": DEST_PATH + "/Data/" + TH_NAME + ".th",
"selector": survey.therion_id,
"th_name": DEST_PATH + "/Data/" + TH_NAME,
"scale": SCALE,
}
log, tmpdir = compile_template(template, template_args, cleanup=False, therion_path=therion_path) log, tmpdir = compile_template(template, template_args, cleanup=False, therion_path=therion_path)
################################################################################################# #################################################################################################
# Parse the Plan XVI file # Parse the Plan XVI file #
th_name_xvi = DEST_PATH + "/Data/" + TH_NAME + "-Plan.xvi" #################################################################################################
if args.update == "th2":
th_name_xvi = DEST_PATH + "/" + TH_NAME + "-Plan.xvi"
else :
th_name_xvi = DEST_PATH + "/Data/" + TH_NAME + "-Plan.xvi"
print(f"{Colors.GREEN}Parsing plan XVI file:\t{Colors.ENDC}{th_name_xvi}") print(f"{Colors.GREEN}Parsing plan XVI file:\t{Colors.ENDC}{th_name_xvi}")
stations = {} stations = {}
@@ -592,8 +636,10 @@ if __name__ == u'__main__':
station2 = stations[key2][2] if key2 in stations else None station2 = stations[key2][2] if key2 in stations else None
lines.append([x1, y1, x2, y2, station1, station2]) lines.append([x1, y1, x2, y2, station1, station2])
# shutil.rmtree(tmpdir) # shutil.rmtree(tmpdir)
if args.update == "th2":
th2_name = DEST_PATH + "/Data/" + TH_NAME th2_name = DEST_PATH + "/" + TH_NAME
else :
th2_name = DEST_PATH + "/Data/" + TH_NAME
output_path = f'{th2_name}-{PROJECTION}.{FORMAT}' output_path = f'{th2_name}-{PROJECTION}.{FORMAT}'
scrap_to_add = int(len(stations)/station_by_scrap)-1 scrap_to_add = int(len(stations)/station_by_scrap)-1
@@ -715,9 +761,14 @@ endscrap
) )
################################################################################################# #################################################################################################
th_name_xvi = DEST_PATH + "/Data/" + TH_NAME + "-Extended.xvi" # Parse the Extended XVI file #
#################################################################################################
if args.update == "th2":
th_name_xvi = DEST_PATH + "/" + TH_NAME + "-Extended.xvi"
else :
th_name_xvi = DEST_PATH + "/Data/" + TH_NAME + "-Extended.xvi"
print(f"{Colors.GREEN}Parsing extended XVI file:\t{Colors.ENDC}{th_name_xvi}") print(f"{Colors.GREEN}Parsing extended XVI file:\t{Colors.ENDC}{th_name_xvi}")
# Parse the Extended XVI file # Parse the Extended XVI file
@@ -779,7 +830,10 @@ endscrap
lines.append([x1, y1, x2, y2, station1, station2]) lines.append([x1, y1, x2, y2, station1, station2])
shutil.rmtree(tmpdir) shutil.rmtree(tmpdir)
th2_name = DEST_PATH + "/Data/" + TH_NAME if args.update == "th2":
th2_name = DEST_PATH + "/" + TH_NAME
else :
th2_name = DEST_PATH + "/Data/" + TH_NAME
output_path = f'{th2_name}-Extended.{FORMAT}' output_path = f'{th2_name}-Extended.{FORMAT}'
print(f"{Colors.GREEN}Writing output to:\t\t{Colors.ENDC}{output_path}") print(f"{Colors.GREEN}Writing output to:\t\t{Colors.ENDC}{output_path}")
@@ -894,34 +948,40 @@ endscrap
) )
#################################################################################################
# Update -maps files #
#################################################################################################
if args.update == "":
config_vars = {
'fileName': TH_NAME,
'Author': Author,
'Copyright': Copyright,
'Scale' : SCALE,
'Target' : TARGET,
'map_comment' : map_comment,
'club' : club,
'thanksto' : thanksto,
'datat' : datat,
'wpage' : wpage,
'cs' : cs,
'other_scraps_plan' : other_scraps_plan,
'other_scraps_extended' : other_scraps_extended,
'file_info' : f"# File generated by pyCreate_th2.py version {Version} date: {datetime.now().strftime("%Y.%m.%d-%H:%M:%S")}",
}
process_template(DEST_PATH + '/template-maps.th', config_vars, DEST_PATH + '/' + TH_NAME + '-maps.th')
################################################################################################# #################################################################################################
config_vars = { # Final therion compilation #
'fileName': TH_NAME, #################################################################################################
'Author': Author,
'Copyright': Copyright,
'Scale' : SCALE,
'Target' : TARGET,
'map_comment' : map_comment,
'club' : club,
'thanksto' : thanksto,
'datat' : datat,
'wpage' : wpage,
'cs' : cs,
'other_scraps_plan' : other_scraps_plan,
'other_scraps_extended' : other_scraps_extended,
'file_info' : f"# File generated by pyCreate_th2.py version {Version} date: {datetime.now().strftime("%Y.%m.%d-%H:%M:%S")}",
}
process_template(DEST_PATH + '/template-maps.th', config_vars, DEST_PATH + '/' + TH_NAME + '-maps.th') if args.update == "":
if final_therion_exe == True:
print(f"{Colors.GREEN}Final therion compilation{Colors.ENDC}")
PATH = os.path.dirname(args.survey_file) + "/" + TH_NAME + "/" + TH_NAME + ".thconfig"
compile_file(PATH, therion_path=therion_path)
if final_therion_exe == True:
print(f"{Colors.GREEN}Final therion compilation{Colors.ENDC}")
PATH = os.path.dirname(args.survey_file) + "/" + TH_NAME + "/" + TH_NAME + ".thconfig"
compile_file(PATH, therion_path=therion_path)