@@ -12,8 +12,11 @@ parser.add_argument('-d', '--dir', type=str, default='templates', help='Template
1212parser .add_argument ('-t' , '--template' , type = str , help = 'Template to render.' )
1313parser .add_argument ('-o' , '--output' , type = str , help = 'Output file to write.' )
1414parser .add_argument ('-c' , '--config' , type = str , help = 'Config file to load.' )
15+ parser .add_argument ('-p' , '--print' , action = 'store_true' , help = 'Print the list of configurations to be created without creating them.' )
1516args = parser .parse_args ()
1617
18+ outputs = [args .output ]
19+
1720# template
1821env = jinja2 .Environment (
1922 loader = jinja2 .FileSystemLoader (args .dir ),
@@ -27,8 +30,9 @@ if args.config is not None:
2730 config = yaml .safe_load (f )
2831
2932# render the template
30- with open (args .output , 'w' ) as output :
31- output .write (template .render (** config ))
33+ if not args .print :
34+ with open (args .output , 'w' ) as output :
35+ output .write (template .render (** config ))
3236
3337# If the config contains far_forward or far_backward create new xml files with ebeam and pbeam set
3438if 'features' in config and ('far_forward' in config ['features' ] or 'far_backward' in config ['features' ]):
@@ -52,11 +56,19 @@ if 'features' in config and ('far_forward' in config['features'] or 'far_backwar
5256 ]
5357
5458 for values in ebeam_pbeam_values :
59+ # Create a new output filename based on the ebeam and pbeam values
60+ new_output = args .output .replace ('.xml' , f"_{ values ['ebeam' ]} x{ values ['pbeam' ]} .xml" )
61+ outputs .append (new_output )
62+
5563 # Create a new config dictionary with the current ebeam and pbeam values
5664 new_config = config .copy ()
5765 new_config .update (values )
66+
67+ if not args .print :
68+ with open (new_output , 'w' ) as output :
69+ output .write (template .render (** new_config ))
5870
59- # Render the template with the new config
60- new_output = args . output . replace ( '.xml' , f"_ { values [ 'ebeam' ] } x { values [ 'pbeam' ] } .xml" )
61- with open ( new_output , 'w' ) as output :
62- output . write ( template . render ( ** new_config ))
71+ if args . print :
72+ for output in outputs :
73+ # Print the output configuration name without the xml extension
74+ print ( os . path . basename ( output ). replace ( '.xml' , '' ))
0 commit comments