[initcpiocfg] code tidy up
This commit is contained in:
parent
1f5bdef96e
commit
df256b608a
@ -12,7 +12,6 @@
|
|||||||
# Calamares is Free Software: see the License-Identifier above.
|
# Calamares is Free Software: see the License-Identifier above.
|
||||||
#
|
#
|
||||||
|
|
||||||
import libcalamares
|
|
||||||
from libcalamares.utils import debug, target_env_call
|
from libcalamares.utils import debug, target_env_call
|
||||||
import os
|
import os
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
@ -41,7 +40,7 @@ def cpuinfo():
|
|||||||
|
|
||||||
nprocs = 0
|
nprocs = 0
|
||||||
|
|
||||||
with open('/proc/cpuinfo') as cpuinfo_file:
|
with open("/proc/cpuinfo") as cpuinfo_file:
|
||||||
for line in cpuinfo_file:
|
for line in cpuinfo_file:
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
# end of one processor
|
# end of one processor
|
||||||
@ -50,11 +49,11 @@ def cpuinfo():
|
|||||||
# Reset
|
# Reset
|
||||||
procinfo = OrderedDict()
|
procinfo = OrderedDict()
|
||||||
else:
|
else:
|
||||||
if len(line.split(':')) == 2:
|
if len(line.split(":")) == 2:
|
||||||
splitted_line = line.split(':')[1].strip()
|
splitted_line = line.split(":")[1].strip()
|
||||||
procinfo[line.split(':')[0].strip()] = splitted_line
|
procinfo[line.split(":")[0].strip()] = splitted_line
|
||||||
else:
|
else:
|
||||||
procinfo[line.split(':')[0].strip()] = ''
|
procinfo[line.split(":")[0].strip()] = ""
|
||||||
|
|
||||||
return cpu_info
|
return cpu_info
|
||||||
|
|
||||||
@ -78,14 +77,14 @@ def write_mkinitcpio_lines(hooks, modules, files, root_mount_point):
|
|||||||
|
|
||||||
for i in range(len(mklins)):
|
for i in range(len(mklins)):
|
||||||
if mklins[i].startswith("HOOKS"):
|
if mklins[i].startswith("HOOKS"):
|
||||||
joined_hooks = ' '.join(hooks)
|
joined_hooks = " ".join(hooks)
|
||||||
mklins[i] = "HOOKS=\"{!s}\"".format(joined_hooks)
|
mklins[i] = "HOOKS='{!s}'".format(joined_hooks)
|
||||||
elif mklins[i].startswith("MODULES"):
|
elif mklins[i].startswith("MODULES"):
|
||||||
joined_modules = ' '.join(modules)
|
joined_modules = ' '.join(modules)
|
||||||
mklins[i] = "MODULES=\"{!s}\"".format(joined_modules)
|
mklins[i] = "MODULES='{!s}'".format(joined_modules)
|
||||||
elif mklins[i].startswith("FILES"):
|
elif mklins[i].startswith("FILES"):
|
||||||
joined_files = ' '.join(files)
|
joined_files = ' '.join(files)
|
||||||
mklins[i] = "FILES=\"{!s}\"".format(joined_files)
|
mklins[i] = "FILES='{!s}'".format(joined_files)
|
||||||
|
|
||||||
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
||||||
|
|
||||||
@ -112,10 +111,17 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
|||||||
"""
|
"""
|
||||||
cpu = cpuinfo()
|
cpu = cpuinfo()
|
||||||
swap_uuid = ""
|
swap_uuid = ""
|
||||||
btrfs = ""
|
btrfs = False
|
||||||
lvm2 = ""
|
lvm2 = False
|
||||||
hooks = ["base", "udev", "autodetect", "modconf", "block", "keyboard",
|
hooks = [
|
||||||
"keymap"]
|
"base",
|
||||||
|
"udev",
|
||||||
|
"autodetect",
|
||||||
|
"modconf",
|
||||||
|
"block",
|
||||||
|
"keyboard",
|
||||||
|
"keymap"
|
||||||
|
]
|
||||||
modules = []
|
modules = []
|
||||||
files = []
|
files = []
|
||||||
encrypt_hook = False
|
encrypt_hook = False
|
||||||
@ -137,10 +143,10 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
|||||||
openswap_hook = True
|
openswap_hook = True
|
||||||
|
|
||||||
if partition["fs"] == "btrfs":
|
if partition["fs"] == "btrfs":
|
||||||
btrfs = "yes"
|
btrfs = True
|
||||||
|
|
||||||
if "lvm2" in partition["fs"]:
|
if "lvm2" in partition["fs"]:
|
||||||
lvm2 = "yes"
|
lvm2 = True
|
||||||
|
|
||||||
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
|
if partition["mountPoint"] == "/" and "luksMapperName" in partition:
|
||||||
encrypt_hook = True
|
encrypt_hook = True
|
||||||
@ -156,11 +162,12 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
|||||||
hooks.append("plymouth-encrypt")
|
hooks.append("plymouth-encrypt")
|
||||||
else:
|
else:
|
||||||
hooks.append("encrypt")
|
hooks.append("encrypt")
|
||||||
|
crypto_file = "crypto_keyfile.bin"
|
||||||
if not unencrypted_separate_boot and \
|
if not unencrypted_separate_boot and \
|
||||||
os.path.isfile(
|
os.path.isfile(
|
||||||
os.path.join(root_mount_point, "crypto_keyfile.bin")
|
os.path.join(root_mount_point, crypto_file)
|
||||||
):
|
):
|
||||||
files.append("/crypto_keyfile.bin")
|
files.append("/{!s}".format(crypto_file))
|
||||||
|
|
||||||
if lvm2:
|
if lvm2:
|
||||||
hooks.append("lvm2")
|
hooks.append("lvm2")
|
||||||
@ -172,10 +179,10 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
|||||||
else:
|
else:
|
||||||
hooks.extend(["filesystems"])
|
hooks.extend(["filesystems"])
|
||||||
|
|
||||||
if btrfs == "yes" and cpu['proc0']['vendor_id'].lower() != "genuineintel":
|
cpu_intel = "genuineintel"
|
||||||
|
if btrfs and cpu["proc0"]["vendor_id"].lower() != cpu_intel:
|
||||||
modules.append("crc32c")
|
modules.append("crc32c")
|
||||||
elif (btrfs == "yes"
|
elif (btrfs and cpu["proc0"]["vendor_id"].lower() == cpu_intel):
|
||||||
and cpu['proc0']['vendor_id'].lower() == "genuineintel"):
|
|
||||||
modules.append("crc32c-intel")
|
modules.append("crc32c-intel")
|
||||||
else:
|
else:
|
||||||
hooks.append("fsck")
|
hooks.append("fsck")
|
||||||
@ -185,7 +192,7 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
|||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""
|
"""
|
||||||
Calls routine with given parameters to modify '/etc/mkinitcpio.conf'.
|
Calls routine with given parameters to modify "/etc/mkinitcpio.conf".
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
@ -195,11 +202,11 @@ def run():
|
|||||||
if not partitions:
|
if not partitions:
|
||||||
libcalamares.utils.warning("partitions is empty, {!s}".format(partitions))
|
libcalamares.utils.warning("partitions is empty, {!s}".format(partitions))
|
||||||
return (_("Configuration Error"),
|
return (_("Configuration Error"),
|
||||||
_("No partitions are defined for <pre>{!s}</pre> to use." ).format("initcpiocfg"))
|
_("No partitions are defined for <pre>{!s}</pre> to use.").format("initcpiocfg"))
|
||||||
if not root_mount_point:
|
if not root_mount_point:
|
||||||
libcalamares.utils.warning("rootMountPoint is empty, {!s}".format(root_mount_point))
|
libcalamares.utils.warning("rootMountPoint is empty, {!s}".format(root_mount_point))
|
||||||
return (_("Configuration Error"),
|
return (_("Configuration Error"),
|
||||||
_("No root mount point is given for <pre>{!s}</pre> to use." ).format("initcpiocfg"))
|
_("No root mount point is given for <pre>{!s}</pre> to use.").format("initcpiocfg"))
|
||||||
|
|
||||||
modify_mkinitcpio_conf(partitions, root_mount_point)
|
modify_mkinitcpio_conf(partitions, root_mount_point)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user