47 lines
1.9 KiB
Python
47 lines
1.9 KiB
Python
# funct_gen.py
|
|
|
|
import os
|
|
import time
|
|
|
|
|
|
# Function to generate the DMUAUT_CFG.SPF configuration file and save selected parameter sets
|
|
def generate_config_spf(folder_output, input_vars, selected_params):
|
|
# Get the current timestamp for folder name (format: YYMMDD_HHmmSS)
|
|
timestamp = time.strftime("%y%m%d_%H%M%S")
|
|
folder_path = os.path.join(folder_output, f"{timestamp}")
|
|
|
|
# Create the folder with the timestamp
|
|
if not os.path.exists(folder_path):
|
|
os.makedirs(folder_path)
|
|
|
|
# Define the file path for the SPF configuration file
|
|
spf_file_path = os.path.join(folder_path, "DMUAUT_CFG.SPF")
|
|
|
|
# Generate the SPF file content
|
|
with open(spf_file_path, "w") as spf_file:
|
|
spf_file.write(f"; CFG FILE FOR DMU50 AUTOMATION\n")
|
|
spf_file.write(f"; GENERATED: {timestamp}\n")
|
|
spf_file.write("; ---------------------------------------------------\n")
|
|
|
|
# Iterate over the input variables (each group), and write them into the file
|
|
for group_name, variables in input_vars.items():
|
|
for var_name, var_value in variables.items():
|
|
spf_file.write(f"{var_name.upper()} = {var_value.get()}\n")
|
|
spf_file.write("\n")
|
|
spf_file.write("; ---------------------------------------------------\n")
|
|
|
|
# Define the file path for the text file with selected parameter sets
|
|
selected_params_file_path = os.path.join(folder_path, "selected_param_sets.txt")
|
|
|
|
# Save the currently selected parameter sets in a .txt file
|
|
with open(selected_params_file_path, "w") as param_file:
|
|
param_file.write("Selected Parameter Sets:\n")
|
|
for group_name, param_name in selected_params.items():
|
|
# Extract the actual value from the tk.StringVar object using .get()
|
|
param_file.write(f"{group_name}: {param_name.get()}\n")
|
|
|
|
print(f"Configuration files saved in {folder_path}")
|
|
|
|
# def generate_config_spf():
|
|
# tbd
|