Skip to content

Commit a13a8ce

Browse files
committed
gen_partition: refactor line reading logic
Simplify logic for readability. Signed-off-by: Loïc Minier <loic.minier@oss.qualcomm.com>
1 parent 5c95a7e commit a13a8ce

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

gen_partition.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,21 @@ def generate_partition_xml(disk_params, partitions, output_xml):
258258
print(str(argerr))
259259
usage()
260260
f = open(input_file)
261-
line = f.readline()
262-
while line:
263-
if not re.search(r"^\s*#", line) and not re.search(r"^\s*$", line):
264-
line = line.strip()
265-
if re.search("^--disk", line):
266-
if disk_entry is None:
267-
disk_entry = line
268-
else:
269-
print("%s %s" % (sys.argv[1], disk_entry_err_msg))
270-
print("%s\n%s" % (disk_entry, line))
271-
sys.exit(1)
272-
elif re.search("^--partition", line):
273-
partition_entries.append(line)
261+
while (line := f.readline()):
262+
if re.search(r"^\s*#", line) or re.search(r"^\s*$", line):
263+
continue
264+
line = line.strip()
265+
if re.search("^--disk", line):
266+
if disk_entry is None:
267+
disk_entry = line
274268
else:
275-
print("Ignoring %s" % (line))
276-
line = f.readline()
269+
print("%s %s" % (sys.argv[1], disk_entry_err_msg))
270+
print("%s\n%s" % (disk_entry, line))
271+
sys.exit(1)
272+
elif re.search("^--partition", line):
273+
partition_entries.append(line)
274+
else:
275+
print("Ignoring %s" % (line))
277276
f.close()
278277
except Exception as e:
279278
print("Error: ", e)

0 commit comments

Comments
 (0)