[initcpio] Refactor file-writing
- iterate over the lines of the source file, rather than over indexes, and make clear that the hooks, modules and files lines are replaced, rather than merged. - this calls write() more often, but it's only a few lines
This commit is contained in:
parent
12cd9dd5b2
commit
a4c714238f
@ -119,21 +119,18 @@ def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
|
|||||||
"""
|
"""
|
||||||
mklins = get_host_initcpio()
|
mklins = get_host_initcpio()
|
||||||
|
|
||||||
for i in range(len(mklins)):
|
target_path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
||||||
if mklins[i].startswith("HOOKS"):
|
with open(target_path, "w") as mkinitcpio_file:
|
||||||
joined_hooks = ' '.join(hooks)
|
for line in mklins:
|
||||||
mklins[i] = "HOOKS=\"{!s}\"".format(joined_hooks)
|
# Replace HOOKS, MODULES and FILES lines with what we
|
||||||
elif mklins[i].startswith("MODULES"):
|
# have found via find_initcpio_features()
|
||||||
joined_modules = ' '.join(modules)
|
if line.startswith("HOOKS"):
|
||||||
mklins[i] = "MODULES=\"{!s}\"".format(joined_modules)
|
line = "HOOKS=\"{!s}\"".format(' '.join(hooks))
|
||||||
elif mklins[i].startswith("FILES"):
|
elif line.startswith("MODULES"):
|
||||||
joined_files = ' '.join(files)
|
line = "MODULES=\"{!s}\"".format(' '.join(modules))
|
||||||
mklins[i] = "FILES=\"{!s}\"".format(joined_files)
|
elif lines.startswith("FILES"):
|
||||||
|
line = "FILES=\"{!s}\"".format(' '.join(files))
|
||||||
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
mkinitcpio_file.write(line + "\n")
|
||||||
|
|
||||||
with open(path, "w") as mkinitcpio_file:
|
|
||||||
mkinitcpio_file.write("\n".join(mklins) + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
def find_initcpio_features(partitions, root_mount_point):
|
def find_initcpio_features(partitions, root_mount_point):
|
||||||
|
Loading…
Reference in New Issue
Block a user