Merge pull request #739 from siduction/pep8-grubcfg

Fixed pep8 whining in module grubcfg
This commit is contained in:
adriaandegroot 2017-06-06 12:20:46 +02:00 committed by GitHub
commit eb2c14b7f6

View File

@ -5,6 +5,7 @@
# #
# Copyright 2014-2015, Philip Müller <philm@manjaro.org> # Copyright 2014-2015, Philip Müller <philm@manjaro.org>
# Copyright 2015-2017, Teo Mrnjavac <teo@kde.org> # Copyright 2015-2017, Teo Mrnjavac <teo@kde.org>
# Copyright 2017, Alf Gaida <agaida@siduction.org>
# #
# Calamares is free software: you can redistribute it and/or modify # Calamares is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,7 +26,8 @@ import re
def modify_grub_default(partitions, root_mount_point, distributor): def modify_grub_default(partitions, root_mount_point, distributor):
""" Configures '/etc/default/grub' for hibernation and plymouth. """
Configures '/etc/default/grub' for hibernation and plymouth.
:param partitions: :param partitions:
:param root_mount_point: :param root_mount_point:
@ -35,7 +37,9 @@ def modify_grub_default(partitions, root_mount_point, distributor):
default_dir = os.path.join(root_mount_point, "etc/default") default_dir = os.path.join(root_mount_point, "etc/default")
default_grub = os.path.join(default_dir, "grub") default_grub = os.path.join(default_dir, "grub")
distributor_replace = distributor.replace("'", "'\\''") distributor_replace = distributor.replace("'", "'\\''")
dracut_bin = libcalamares.utils.target_env_call(["sh", "-c", "which dracut"]) dracut_bin = libcalamares.utils.target_env_call(
["sh", "-c", "which dracut"]
)
use_splash = "" use_splash = ""
swap_uuid = "" swap_uuid = ""
swap_outer_uuid = "" swap_outer_uuid = ""
@ -51,20 +55,26 @@ def modify_grub_default(partitions, root_mount_point, distributor):
if partition["fs"] == "linuxswap": if partition["fs"] == "linuxswap":
swap_uuid = partition["uuid"] swap_uuid = partition["uuid"]
if partition["fs"] == "linuxswap" and "luksMapperName" in partition: if (partition["fs"] == "linuxswap"
and "luksMapperName" in partition):
swap_outer_uuid = partition["luksUuid"] swap_outer_uuid = partition["luksUuid"]
if partition["mountPoint"] == "/" and "luksMapperName" in partition: if (partition["mountPoint"] == "/"
cryptdevice_params = ["rd.luks.uuid={!s}".format(partition["luksUuid"])] and "luksMapperName" in partition):
cryptdevice_params = [
"rd.luks.uuid={!s}".format(partition["luksUuid"])
]
else: else:
for partition in partitions: for partition in partitions:
if partition["fs"] == "linuxswap": if partition["fs"] == "linuxswap":
swap_uuid = partition["uuid"] swap_uuid = partition["uuid"]
if partition["mountPoint"] == "/" and "luksMapperName" in partition: if (partition["mountPoint"] == "/"
and "luksMapperName" in partition):
cryptdevice_params = [ cryptdevice_params = [
"cryptdevice=UUID={!s}:{!s}".format(partition["luksUuid"], "cryptdevice=UUID={!s}:{!s}".format(
partition["luksMapperName"]), partition["luksUuid"], partition["luksMapperName"]
),
"root=/dev/mapper/{!s}".format(partition["luksMapperName"]) "root=/dev/mapper/{!s}".format(partition["luksMapperName"])
] ]
@ -101,7 +111,9 @@ def modify_grub_default(partitions, root_mount_point, distributor):
for i in range(len(lines)): for i in range(len(lines)):
if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"): if lines[i].startswith("#GRUB_CMDLINE_LINUX_DEFAULT"):
kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(
" ".join(kernel_params)
)
lines[i] = kernel_cmd lines[i] = kernel_cmd
have_kernel_cmd = True have_kernel_cmd = True
elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"): elif lines[i].startswith("GRUB_CMDLINE_LINUX_DEFAULT"):
@ -118,20 +130,26 @@ def modify_grub_default(partitions, root_mount_point, distributor):
for existing_param in existing_params: for existing_param in existing_params:
existing_param_name = existing_param.split("=")[0] existing_param_name = existing_param.split("=")[0]
if existing_param_name not in ["quiet", "resume", "splash"]: # the only ones we ever add # the only ones we ever add
if existing_param_name not in [
"quiet", "resume", "splash"]:
kernel_params.append(existing_param) kernel_params.append(existing_param)
kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(
" ".join(kernel_params)
)
lines[i] = kernel_cmd lines[i] = kernel_cmd
have_kernel_cmd = True have_kernel_cmd = True
elif lines[i].startswith("#GRUB_DISTRIBUTOR") or lines[i].startswith("GRUB_DISTRIBUTOR"): elif (lines[i].startswith("#GRUB_DISTRIBUTOR")
or lines[i].startswith("GRUB_DISTRIBUTOR")):
lines[i] = distributor_line lines[i] = distributor_line
have_distributor_line = True have_distributor_line = True
else: else:
lines = [] lines = []
if "defaults" in libcalamares.job.configuration: if "defaults" in libcalamares.job.configuration:
for key, value in libcalamares.job.configuration["defaults"].items(): for key, value in libcalamares.job.configuration[
"defaults"].items():
if value.__class__.__name__ == "bool": if value.__class__.__name__ == "bool":
if value: if value:
escaped_value = "true" escaped_value = "true"
@ -143,7 +161,9 @@ def modify_grub_default(partitions, root_mount_point, distributor):
lines.append("{!s}='{!s}'".format(key, escaped_value)) lines.append("{!s}='{!s}'".format(key, escaped_value))
if not have_kernel_cmd: if not have_kernel_cmd:
kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(" ".join(kernel_params)) kernel_cmd = "GRUB_CMDLINE_LINUX_DEFAULT=\"{!s}\"".format(
" ".join(kernel_params)
)
lines.append(kernel_cmd) lines.append(kernel_cmd)
if not have_distributor_line: if not have_distributor_line:
@ -159,14 +179,16 @@ def modify_grub_default(partitions, root_mount_point, distributor):
def run(): def run():
""" Calls routine with given parameters to modify '/etc/default/grub'. """
Calls routine with given parameters to modify '/etc/default/grub'.
:return: :return:
""" """
fw_type = libcalamares.globalstorage.value("firmwareType") fw_type = libcalamares.globalstorage.value("firmwareType")
if libcalamares.globalstorage.value("bootLoader") is None and fw_type != "efi": if (libcalamares.globalstorage.value("bootLoader") is None
and fw_type != "efi"):
return None return None
partitions = libcalamares.globalstorage.value("partitions") partitions = libcalamares.globalstorage.value("partitions")
@ -175,7 +197,8 @@ def run():
esp_found = False esp_found = False
for partition in partitions: for partition in partitions:
if partition["mountPoint"] == libcalamares.globalstorage.value("efiSystemPartition"): if (partition["mountPoint"]
== libcalamares.globalstorage.value("efiSystemPartition")):
esp_found = True esp_found = True
if not esp_found: if not esp_found: