Merge pull request #2234 from ArrayBolt3/calamares

[grubcfg] Don't silently ignore missing grub configuration items
This commit is contained in:
dalto8 2023-12-02 21:19:14 +00:00 committed by GitHub
commit 82fd10408c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import libcalamares
import fileinput import fileinput
import os import os
import re import re
import shutil
import gettext import gettext
_ = gettext.translation("calamares-python", _ = gettext.translation("calamares-python",
@ -95,19 +96,32 @@ def update_existing_config(default_grub, grub_config_items):
:param default_grub: The absolute path to the grub config file :param default_grub: The absolute path to the grub config file
:param grub_config_items: A dict holding the key value pairs representing the items :param grub_config_items: A dict holding the key value pairs representing the items
""" """
for line in fileinput.input(default_grub, inplace=True):
line = line.strip() default_grub_orig = default_grub + ".calamares"
if "=" in line: shutil.move(default_grub, default_grub_orig)
# This may be a key, strip the leading comment if it has one
key = line.lstrip("#").split("=")[0].strip()
# check if this is one of the keys we care about with open(default_grub, "w") as grub_file:
if key in grub_config_items.keys(): with open(default_grub_orig, "r") as grub_orig_file:
print(f"{key}={grub_config_items[key]}") for line in grub_orig_file.readlines():
else: line = line.strip()
print(line) if "=" in line:
else: # This may be a key, strip the leading comment if it has one
print(line) key = line.lstrip("#").split("=")[0].strip()
# check if this is noe of the keys we care about
if key in grub_config_items.keys():
print(f"{key}={grub_config_items[key]}", file=grub_file)
del grub_config_items[key]
else:
print(line, file=grub_file)
else:
print(line, file=grub_file)
if len(grub_config_items) != 0:
for dict_key, dict_val in grub_config_items.items():
print(f"{dict_key}={dict_val}", file=grub_file)
os.remove(default_grub_orig)
def modify_grub_default(partitions, root_mount_point, distributor): def modify_grub_default(partitions, root_mount_point, distributor):