[initcpiocfg] Refactor

- Read the host /etc/mkinitcpio.cfg in one function rather
  than hiding it inside the writer
This commit is contained in:
Adriaan de Groot 2021-09-21 13:18:01 +02:00
parent 60e495bd8c
commit 12cd9dd5b2

View File

@ -91,6 +91,23 @@ class cpuinfo(object):
return cpu_info return cpu_info
def get_host_initcpio():
"""
Reads the host system mkinitcpio.conf and returns all
the lines from that file, or an empty list if it does
not exist.
"""
hostfile = "/etc/mkinitcpio.conf"
try:
with open(hostfile, "r") as mkinitcpio_file:
mklins = [x.strip() for x in mkinitcpio_file.readlines()]
except FileNotFoundError:
libcalamares.utils.debug("Could not open host file '%s'" % hostfile)
mklins = []
return mklins
def write_mkinitcpio_lines(hooks, modules, files, root_mount_point): def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
""" """
Set up mkinitcpio.conf. Set up mkinitcpio.conf.
@ -100,13 +117,7 @@ def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
:param files: :param files:
:param root_mount_point: :param root_mount_point:
""" """
hostfile = "/etc/mkinitcpio.conf" mklins = get_host_initcpio()
try:
with open(hostfile, "r") as mkinitcpio_file:
mklins = [x.strip() for x in mkinitcpio_file.readlines()]
except FileNotFoundError:
libcalamares.utils.debug("Could not open host file '%s'" % hostfile)
mklins = []
for i in range(len(mklins)): for i in range(len(mklins)):
if mklins[i].startswith("HOOKS"): if mklins[i].startswith("HOOKS"):