Skip to content

Commit b86ca96

Browse files
committed
grml2usb: remove_default_entry: avoid using fileinput
1 parent 893968a commit b86ca96

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

grml2usb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,12 +1477,16 @@ def remove_default_entry(filename: str) -> None:
14771477
14781478
@filename: syslinux config file
14791479
"""
1480-
default_re = re.compile(r"^(\s*menu\s*default\s*)$", re.I)
1481-
for line in fileinput.input(filename, inplace=True):
1482-
if default_re.match(line):
1483-
continue
1484-
sys.stdout.write(line)
1485-
fileinput.close()
1480+
default_re = re.compile(r"^(\s*menu\s*default\s*)$", re.I | re.MULTILINE)
1481+
lines = []
1482+
with open(filename, "r+") as fh:
1483+
for line in fh.read().split("\n"):
1484+
if default_re.match(line):
1485+
continue
1486+
lines.append(line)
1487+
fh.seek(0)
1488+
fh.truncate()
1489+
fh.write("\n".join(lines))
14861490

14871491

14881492
def handle_syslinux_config(

0 commit comments

Comments
 (0)