1+ import argparse
2+ import os
3+ import xml .etree .ElementTree as ET
4+
5+ def generate_run_xml (problem_number ):
6+ # Define paths
7+ script_dir = "scripts"
8+ run_dir = ".run"
9+ template_file = os .path .join (script_dir , "Main.run.xml" )
10+ output_file = os .path .join (run_dir , f"MainP{ problem_number } .run.xml" )
11+
12+ # Ensure .run directory exists
13+ os .makedirs (run_dir , exist_ok = True )
14+
15+ # Read the template XML file
16+ with open (template_file , 'r' ) as file :
17+ xml_content = file .read ()
18+
19+ # Replace p140 with the new problem number
20+ new_xml_content = xml_content .replace ('p140' , f'p{ problem_number } ' )
21+ new_xml_content = new_xml_content .replace ('name="Main"' , f'name="MainP{ problem_number } "' )
22+
23+ # Write the new XML file
24+ with open (output_file , 'w' ) as file :
25+ file .write (new_xml_content )
26+
27+ print (f"Generated { output_file } for problem p{ problem_number } " )
28+
29+ def main ():
30+ parser = argparse .ArgumentParser (description = "Generate a new Main run XML file for a given problem number." )
31+ parser .add_argument ("problem_number" , type = str , help = "Problem number (e.g., 138 for p138)" )
32+ args = parser .parse_args ()
33+
34+ generate_run_xml (args .problem_number )
35+
36+ if __name__ == "__main__" :
37+ main ()
0 commit comments