@@ -12,8 +12,11 @@ parser.add_argument('-d', '--dir', type=str, default='templates', help='Template
12
12
parser .add_argument ('-t' , '--template' , type = str , help = 'Template to render.' )
13
13
parser .add_argument ('-o' , '--output' , type = str , help = 'Output file to write.' )
14
14
parser .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.' )
15
16
args = parser .parse_args ()
16
17
18
+ outputs = [args .output ]
19
+
17
20
# template
18
21
env = jinja2 .Environment (
19
22
loader = jinja2 .FileSystemLoader (args .dir ),
@@ -27,8 +30,9 @@ if args.config is not None:
27
30
config = yaml .safe_load (f )
28
31
29
32
# 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 ))
32
36
33
37
# If the config contains far_forward or far_backward create new xml files with ebeam and pbeam set
34
38
if '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
52
56
]
53
57
54
58
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
+
55
63
# Create a new config dictionary with the current ebeam and pbeam values
56
64
new_config = config .copy ()
57
65
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 ))
58
70
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