@@ -69,9 +69,6 @@ def usage():
6969}
7070
7171##################################################################
72- # store entries read from input file
73- disk_entry = None
74- partition_entries = []
7572# store partition image map passed from command line
7673partition_image_map = {}
7774input_file = None
@@ -262,7 +259,6 @@ def generate_partition_xml(disk_params, partitions, output_xml):
262259
263260###############################################################################
264261# main
265- disk_entry_err_msg = "contains more than one --disk entries"
266262
267263if len (sys .argv ) < 3 :
268264 usage ()
@@ -288,27 +284,50 @@ def generate_partition_xml(disk_params, partitions, output_xml):
288284 except Exception as argerr :
289285 print (str (argerr ))
290286 usage ()
287+
288+ # Parse expanded lines into disk sections
289+ disk_sections = [] # list of (disk_line, [partition_lines])
290+ current_disk = None
291+ current_partitions = []
292+
291293 for line in expand_includes (input_file ):
292294 if re .search (r"^\s*#" , line ) or re .search (r"^\s*$" , line ):
293295 continue
294296 if re .search ("^--disk" , line ):
295- if disk_entry is None :
296- disk_entry = line
297- else :
298- print ("%s %s" % (sys .argv [1 ], disk_entry_err_msg ))
299- print ("%s\n %s" % (disk_entry , line ))
300- sys .exit (1 )
297+ if current_disk is not None :
298+ disk_sections .append ((current_disk , current_partitions ))
299+ current_partitions = []
300+ current_disk = line
301301 elif re .search ("^--partition" , line ):
302- partition_entries .append (line )
302+ current_partitions .append (line )
303303 else :
304304 print ("Ignoring %s" % (line ))
305-
305+ if current_disk is not None :
306+ disk_sections .append ((current_disk , current_partitions ))
307+
308+ if not disk_sections :
309+ print ("Error: no --disk entry found in %s" % input_file )
310+ sys .exit (1 )
311+
312+ if output_xml :
313+ if len (disk_sections ) == 1 :
314+ disk_params = parse_disk_entry (disk_sections [0 ][0 ])
315+ partitions = parse_partition_entries (disk_sections [0 ][1 ])
316+ generate_partition_xml (disk_params , partitions , output_xml )
317+ else :
318+ # Multi-disk: derive output filenames by inserting an index before
319+ # the extension, e.g. partitions.xml -> partitions0.xml, partitions1.xml
320+ base , ext = os .path .splitext (output_xml )
321+ for idx , (disk_line , part_lines ) in enumerate (disk_sections ):
322+ disk_params = parse_disk_entry (disk_line )
323+ partitions = parse_partition_entries (part_lines )
324+ out_path = "%s%d%s" % (base , idx , ext )
325+ generate_partition_xml (disk_params , partitions , out_path )
326+ else :
327+ print ("Error: -o is required" )
328+ sys .exit (1 )
306329except Exception as e :
307330 print ("Error: " , e )
308331 sys .exit (1 )
309332
310- disk_params = parse_disk_entry (disk_entry )
311- partitions = parse_partition_entries (partition_entries )
312- generate_partition_xml (disk_params , partitions , output_xml )
313-
314333sys .exit (0 )
0 commit comments