Python Better Docstrings
This commit is contained in:
parent
b8b41bdfdd
commit
113d9db7cb
@ -32,6 +32,11 @@ from libcalamares.utils import check_chroot_call
|
||||
|
||||
|
||||
def get_uuid():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||
print("Root mount point: \"{!s}\"".format(root_mount_point))
|
||||
partitions = libcalamares.globalstorage.value("partitions")
|
||||
@ -44,6 +49,11 @@ def get_uuid():
|
||||
|
||||
|
||||
def get_bootloader_entry_name():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
if "bootloaderEntryName" in libcalamares.job.configuration:
|
||||
return libcalamares.job.configuration["bootloaderEntryName"]
|
||||
else:
|
||||
@ -52,6 +62,11 @@ def get_bootloader_entry_name():
|
||||
|
||||
|
||||
def get_kernel_line(kernel_type):
|
||||
"""
|
||||
|
||||
:param kernel_type:
|
||||
:return:
|
||||
"""
|
||||
if kernel_type == "fallback":
|
||||
if "fallbackKernelLine" in libcalamares.job.configuration:
|
||||
return libcalamares.job.configuration["fallbackKernelLine"]
|
||||
@ -65,6 +80,12 @@ def get_kernel_line(kernel_type):
|
||||
|
||||
|
||||
def create_conf(uuid, conf_path, kernel_line):
|
||||
"""
|
||||
|
||||
:param uuid:
|
||||
:param conf_path:
|
||||
:param kernel_line:
|
||||
"""
|
||||
distribution = get_bootloader_entry_name()
|
||||
kernel = libcalamares.job.configuration["kernel"]
|
||||
img = libcalamares.job.configuration["img"]
|
||||
@ -91,6 +112,10 @@ def create_conf(uuid, conf_path, kernel_line):
|
||||
|
||||
|
||||
def create_loader(loader_path):
|
||||
"""
|
||||
|
||||
:param loader_path:
|
||||
"""
|
||||
distribution = get_bootloader_entry_name()
|
||||
timeout = libcalamares.job.configuration["timeout"]
|
||||
file_name_sanitizer = str.maketrans(" /", "_-")
|
||||
@ -107,6 +132,10 @@ def create_loader(loader_path):
|
||||
|
||||
|
||||
def install_gummiboot(efi_directory):
|
||||
"""
|
||||
|
||||
:param efi_directory:
|
||||
"""
|
||||
print("Bootloader: gummiboot")
|
||||
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
||||
install_efi_directory = install_path + efi_directory
|
||||
@ -134,6 +163,11 @@ def install_gummiboot(efi_directory):
|
||||
|
||||
|
||||
def install_grub(efi_directory, fw_type):
|
||||
"""
|
||||
|
||||
:param efi_directory:
|
||||
:param fw_type:
|
||||
"""
|
||||
if fw_type == "efi":
|
||||
print("Bootloader: grub (efi)")
|
||||
efi_directory_firmware = efi_directory + "/EFI"
|
||||
@ -166,6 +200,11 @@ def install_grub(efi_directory, fw_type):
|
||||
|
||||
|
||||
def prepare_bootloader(fw_type):
|
||||
"""
|
||||
|
||||
:param fw_type:
|
||||
:return:
|
||||
"""
|
||||
efi_boot_loader = libcalamares.job.configuration["efiBootLoader"]
|
||||
efi_directory = libcalamares.globalstorage.value("efiSystemPartition")
|
||||
if fw_type == "efi":
|
||||
@ -194,6 +233,11 @@ def prepare_bootloader(fw_type):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
fw_type = libcalamares.globalstorage.value("firmwareType")
|
||||
prepare_bootloader(fw_type)
|
||||
return None
|
||||
|
@ -44,6 +44,11 @@ desktop_environments = [
|
||||
|
||||
|
||||
def find_desktop_environment(root_mount_point):
|
||||
"""
|
||||
|
||||
:param root_mount_point:
|
||||
:return:
|
||||
"""
|
||||
for desktop_environment in desktop_environments:
|
||||
if os.path.exists(
|
||||
"{!s}{!s}".format(root_mount_point, desktop_environment.executable)) \
|
||||
@ -54,6 +59,12 @@ def find_desktop_environment(root_mount_point):
|
||||
|
||||
|
||||
def have_dm(dm_name, root_mount_point):
|
||||
"""
|
||||
|
||||
:param dm_name:
|
||||
:param root_mount_point:
|
||||
:return:
|
||||
"""
|
||||
return os.path.exists(
|
||||
"{!s}/usr/bin/{!s}".format(root_mount_point, dm_name)) or os.path.exists(
|
||||
"{!s}/usr/sbin/{!s}".format(root_mount_point, dm_name))
|
||||
@ -61,8 +72,14 @@ def have_dm(dm_name, root_mount_point):
|
||||
|
||||
def set_autologin(username, displaymanagers, default_desktop_environment,
|
||||
root_mount_point):
|
||||
""" Enables automatic login for the installed desktop managers """
|
||||
"""
|
||||
Enables automatic login for the installed desktop managers.
|
||||
|
||||
:param username:
|
||||
:param displaymanagers:
|
||||
:param default_desktop_environment:
|
||||
:param root_mount_point:
|
||||
"""
|
||||
if "mdm" in displaymanagers:
|
||||
# Systems with MDM as Desktop Manager
|
||||
mdm_conf_path = os.path.join(root_mount_point, "etc/mdm/custom.conf")
|
||||
@ -206,12 +223,14 @@ def set_autologin(username, displaymanagers, default_desktop_environment,
|
||||
|
||||
|
||||
def run():
|
||||
""" Configure display managers """
|
||||
# We acquire a list of displaymanagers, either from config or (overridden) from globalstorage.
|
||||
# This module will try to set up (including autologin) all the displaymanagers in the list, in that specific order.
|
||||
# Most distros will probably only ship one displaymanager.
|
||||
# If a displaymanager is in the list but not installed, a debugging message is printed and the entry ignored.
|
||||
"""
|
||||
Configure display managers.
|
||||
|
||||
We acquire a list of displaymanagers, either from config or (overridden) from globalstorage.
|
||||
This module will try to set up (including autologin) all the displaymanagers in the list, in that specific order.
|
||||
Most distros will probably only ship one displaymanager.
|
||||
If a displaymanager is in the list but not installed, a debugging message is printed and the entry ignored.
|
||||
"""
|
||||
if "displaymanagers" in libcalamares.job.configuration:
|
||||
displaymanagers = libcalamares.job.configuration["displaymanagers"]
|
||||
|
||||
|
@ -24,10 +24,20 @@ from libcalamares.utils import chroot_call
|
||||
|
||||
|
||||
def run_dracut():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
return chroot_call(['dracut', '-f'])
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
returnCode = run_dracut()
|
||||
if returnCode != 0:
|
||||
return ("Failed to run dracut on the target", "The exit code was {}".format(returnCode))
|
@ -24,6 +24,11 @@ from time import gmtime, strftime
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
os.system("/bin/sh -c \"touch ~/calamares-dummypython\"")
|
||||
accumulator = strftime("%Y-%m-%d %H:%M:%S", gmtime()) + "\n"
|
||||
accumulator += "Calamares version: " + libcalamares.VERSION_SHORT + "\n"
|
||||
|
@ -41,11 +41,20 @@ FS_MAP = {
|
||||
|
||||
|
||||
def mkdir_p(path):
|
||||
"""
|
||||
|
||||
:param path:
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
|
||||
|
||||
def is_ssd_disk(disk_name):
|
||||
"""
|
||||
|
||||
:param disk_name:
|
||||
:return:
|
||||
"""
|
||||
filename = os.path.join("/sys/block", disk_name, "queue/rotational")
|
||||
if not os.path.exists(filename):
|
||||
# Should not happen unless sysfs changes, but better safe than sorry
|
||||
@ -55,11 +64,24 @@ def is_ssd_disk(disk_name):
|
||||
|
||||
|
||||
def disk_name_for_partition(partition):
|
||||
"""
|
||||
|
||||
:param partition:
|
||||
:return:
|
||||
"""
|
||||
name = os.path.basename(partition["device"])
|
||||
return re.sub("[0-9]+$", "", name)
|
||||
|
||||
|
||||
class FstabGenerator(object):
|
||||
"""
|
||||
|
||||
:param partitions:
|
||||
:param root_mount_point:
|
||||
:param mount_options:
|
||||
:param ssd_extra_mount_options:
|
||||
"""
|
||||
|
||||
def __init__(self, partitions, root_mount_point, mount_options,
|
||||
ssd_extra_mount_options):
|
||||
self.partitions = partitions
|
||||
@ -70,17 +92,29 @@ class FstabGenerator(object):
|
||||
self.root_is_ssd = False
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
self.find_ssd_disks()
|
||||
self.generate_fstab()
|
||||
self.create_mount_points()
|
||||
return None
|
||||
|
||||
def find_ssd_disks(self):
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
disks = {disk_name_for_partition(x) for x in self.partitions}
|
||||
self.ssd_disks = {x for x in disks if is_ssd_disk(x)}
|
||||
|
||||
def generate_fstab(self):
|
||||
# Create fstab
|
||||
"""
|
||||
Create fstab.
|
||||
|
||||
"""
|
||||
mkdir_p(os.path.join(self.root_mount_point, "etc"))
|
||||
fstab_path = os.path.join(self.root_mount_point, "etc", "fstab")
|
||||
with open(fstab_path, "w") as fl:
|
||||
@ -102,6 +136,11 @@ class FstabGenerator(object):
|
||||
self.print_fstab_line(dct, file=fl)
|
||||
|
||||
def generate_fstab_line_info(self, partition):
|
||||
"""
|
||||
|
||||
:param partition:
|
||||
:return:
|
||||
"""
|
||||
fs = partition["fs"]
|
||||
mount_point = partition["mountPoint"]
|
||||
disk_name = disk_name_for_partition(partition)
|
||||
@ -136,6 +175,11 @@ class FstabGenerator(object):
|
||||
check=check)
|
||||
|
||||
def print_fstab_line(self, dct, file=None):
|
||||
"""
|
||||
|
||||
:param dct:
|
||||
:param file:
|
||||
"""
|
||||
line = "{:41} {:<14} {:<7} {:<10} 0 {}".format(
|
||||
dct["device"],
|
||||
dct["mount_point"],
|
||||
@ -145,12 +189,21 @@ class FstabGenerator(object):
|
||||
print(line, file=file)
|
||||
|
||||
def create_mount_points(self):
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
for partition in self.partitions:
|
||||
if partition["mountPoint"]:
|
||||
mkdir_p(self.root_mount_point + partition["mountPoint"])
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
gs = libcalamares.globalstorage
|
||||
conf = libcalamares.job.configuration
|
||||
partitions = gs.value("partitions")
|
||||
|
@ -23,6 +23,13 @@ import os
|
||||
|
||||
|
||||
def modify_grub_default(partitions, root_mount_point, distributor):
|
||||
"""
|
||||
|
||||
:param partitions:
|
||||
:param root_mount_point:
|
||||
:param distributor:
|
||||
:return:
|
||||
"""
|
||||
default_dir = os.path.join(root_mount_point, "etc/default")
|
||||
default_grub = os.path.join(default_dir, "grub")
|
||||
distributor_replace = distributor.replace("'", "'\\''")
|
||||
@ -95,6 +102,11 @@ def modify_grub_default(partitions, root_mount_point, distributor):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
partitions = libcalamares.globalstorage.value("partitions")
|
||||
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||
branding = libcalamares.globalstorage.value("branding")
|
||||
|
@ -23,10 +23,19 @@ from libcalamares.utils import check_chroot_call
|
||||
|
||||
|
||||
def run_mkinitcpio():
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
kernel = libcalamares.job.configuration['kernel']
|
||||
check_chroot_call(['mkinitcpio', '-p', kernel])
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
run_mkinitcpio()
|
||||
return None
|
||||
|
@ -30,9 +30,7 @@ def cpuinfo():
|
||||
Return the information in /proc/cpuinfo as a dictionary in the following format:
|
||||
cpu_info['proc0']={...}
|
||||
cpu_info['proc1']={...}
|
||||
|
||||
"""
|
||||
|
||||
cpuinfo = OrderedDict()
|
||||
procinfo = OrderedDict()
|
||||
|
||||
@ -55,8 +53,13 @@ def cpuinfo():
|
||||
|
||||
|
||||
def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
|
||||
""" Set up mkinitcpio.conf """
|
||||
"""
|
||||
Set up mkinitcpio.conf.
|
||||
|
||||
:param hooks:
|
||||
:param modules:
|
||||
:param root_mount_point:
|
||||
"""
|
||||
with open("/etc/mkinitcpio.conf", "r") as mkinitcpio_file:
|
||||
mklins = [x.strip() for x in mkinitcpio_file.readlines()]
|
||||
|
||||
@ -74,8 +77,12 @@ def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
|
||||
|
||||
|
||||
def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
""" Modifies mkinitcpio.conf """
|
||||
"""
|
||||
Modifies mkinitcpio.conf
|
||||
|
||||
:param partitions:
|
||||
:param root_mount_point:
|
||||
"""
|
||||
cpu = cpuinfo()
|
||||
swap_uuid = ""
|
||||
btrfs = ""
|
||||
@ -109,6 +116,11 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
partitions = libcalamares.globalstorage.value("partitions")
|
||||
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||
modify_mkinitcpio_conf(partitions, root_mount_point)
|
||||
|
@ -22,6 +22,11 @@ from libcalamares.utils import chroot_call
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
returnCode = chroot_call(["update-initramfs", "-k", "all", "-u"])
|
||||
if returnCode != 0:
|
||||
return ("Failed to run update-initramfs on the target", "The exit code was {}".format(returnCode))
|
||||
|
@ -24,6 +24,11 @@ from libcalamares.utils import check_chroot_call
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||
enable_systemd = libcalamares.job.configuration["systemd"]
|
||||
enable_dbus = libcalamares.job.configuration["dbus"]
|
||||
|
@ -24,6 +24,11 @@ import libcalamares
|
||||
|
||||
|
||||
def mount_partitions(root_mount_point, partitions):
|
||||
"""
|
||||
|
||||
:param root_mount_point:
|
||||
:param partitions:
|
||||
"""
|
||||
for partition in partitions:
|
||||
if not partition["mountPoint"]:
|
||||
continue
|
||||
@ -44,6 +49,11 @@ def mount_partitions(root_mount_point, partitions):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
root_mount_point = tempfile.mkdtemp(prefix="calamares-root-")
|
||||
partitions = libcalamares.globalstorage.value("partitions")
|
||||
extra_mounts = libcalamares.job.configuration["extraMounts"]
|
||||
|
@ -23,10 +23,18 @@ from libcalamares.utils import check_chroot_call, chroot_call
|
||||
|
||||
|
||||
class PackageManager:
|
||||
"""
|
||||
|
||||
:param backend:
|
||||
"""
|
||||
def __init__(self, backend):
|
||||
self.backend = backend
|
||||
|
||||
def install(self, pkgs):
|
||||
"""
|
||||
|
||||
:param pkgs:
|
||||
"""
|
||||
if self.backend == "packagekit":
|
||||
for pkg in pkgs:
|
||||
check_chroot_call(["pkcon", "-py", "install", pkg])
|
||||
@ -48,6 +56,10 @@ class PackageManager:
|
||||
check_chroot_call(["pacman", "-Sy", "--noconfirm"] + pkgs)
|
||||
|
||||
def remove(self, pkgs):
|
||||
"""
|
||||
|
||||
:param pkgs:
|
||||
"""
|
||||
if self.backend == "packagekit":
|
||||
for pkg in pkgs:
|
||||
check_chroot_call(["pkcon", "-py", "remove", pkg])
|
||||
@ -68,6 +80,11 @@ class PackageManager:
|
||||
|
||||
|
||||
def run_operations(pkgman, entry):
|
||||
"""
|
||||
|
||||
:param pkgman:
|
||||
:param entry:
|
||||
"""
|
||||
for key in entry.keys():
|
||||
if key == "install":
|
||||
pkgman.install(entry[key])
|
||||
@ -76,6 +93,11 @@ def run_operations(pkgman, entry):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
backend = libcalamares.job.configuration.get("backend")
|
||||
if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman"):
|
||||
return ("Bad backend", "backend=\"{}\"".format(backend))
|
||||
|
@ -35,6 +35,13 @@ except ImportError:
|
||||
|
||||
|
||||
class Job:
|
||||
"""
|
||||
|
||||
:param working_path:
|
||||
:param doc:
|
||||
:param cfg_doc:
|
||||
"""
|
||||
|
||||
def __init__(self, working_path, doc, cfg_doc):
|
||||
self.module_name = doc["name"]
|
||||
self.pretty_name = "Testing job " + doc["name"]
|
||||
@ -42,10 +49,19 @@ class Job:
|
||||
self.configuration = cfg_doc
|
||||
|
||||
def setprogress(self, progress):
|
||||
"""
|
||||
|
||||
:param progress:
|
||||
"""
|
||||
print("Job set progress to {}%.".format(progress * 100))
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("moduledir",
|
||||
help="Dir containing the Python module.")
|
||||
|
@ -25,6 +25,11 @@ import libcalamares
|
||||
|
||||
|
||||
def list_mounts(root_mount_point):
|
||||
"""
|
||||
|
||||
:param root_mount_point:
|
||||
:return:
|
||||
"""
|
||||
lst = []
|
||||
for line in open("/etc/mtab").readlines():
|
||||
device, mount_point, _ = line.split(" ", 2)
|
||||
@ -34,6 +39,11 @@ def list_mounts(root_mount_point):
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
||||
if not root_mount_point:
|
||||
return ("No mount point for root partition in globalstorage",
|
||||
|
@ -32,6 +32,12 @@ from libcalamares import *
|
||||
|
||||
|
||||
class UnpackEntry:
|
||||
"""
|
||||
|
||||
:param source:
|
||||
:param sourcefs:
|
||||
:param destination:
|
||||
"""
|
||||
__slots__ = ['source', 'sourcefs', 'destination', 'copied', 'total']
|
||||
|
||||
def __init__(self, source, sourcefs, destination):
|
||||
@ -46,6 +52,11 @@ ON_POSIX = 'posix' in sys.builtin_module_names
|
||||
|
||||
|
||||
def list_excludes(destination):
|
||||
"""
|
||||
|
||||
:param destination:
|
||||
:return:
|
||||
"""
|
||||
lst = []
|
||||
extra_mounts = globalstorage.value("extraMounts")
|
||||
for extra_mount in extra_mounts:
|
||||
@ -56,6 +67,13 @@ def list_excludes(destination):
|
||||
|
||||
|
||||
def file_copy(source, dest, progress_cb):
|
||||
"""
|
||||
|
||||
:param source:
|
||||
:param dest:
|
||||
:param progress_cb:
|
||||
:return:
|
||||
"""
|
||||
# Environment used for executing rsync properly
|
||||
# Setting locale to C (fix issue with tr_TR locale)
|
||||
at_env = os.environ
|
||||
@ -106,11 +124,19 @@ def file_copy(source, dest, progress_cb):
|
||||
|
||||
|
||||
class UnpackOperation:
|
||||
"""
|
||||
|
||||
:param entries:
|
||||
"""
|
||||
def __init__(self, entries):
|
||||
self.entries = entries
|
||||
self.entry_for_source = dict((x.source, x) for x in self.entries)
|
||||
|
||||
def report_progress(self):
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
progress = float(0)
|
||||
for entry in self.entries:
|
||||
if entry.total == 0:
|
||||
@ -124,6 +150,11 @@ class UnpackOperation:
|
||||
job.setprogress(progress)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
source_mount_path = tempfile.mkdtemp()
|
||||
try:
|
||||
for entry in self.entries:
|
||||
@ -161,6 +192,11 @@ class UnpackOperation:
|
||||
shutil.rmtree(source_mount_path)
|
||||
|
||||
def mount_image(self, entry, imgmountdir):
|
||||
"""
|
||||
|
||||
:param entry:
|
||||
:param imgmountdir:
|
||||
"""
|
||||
subprocess.check_call(["mount",
|
||||
entry.source,
|
||||
imgmountdir,
|
||||
@ -169,7 +205,18 @@ class UnpackOperation:
|
||||
"-o", "loop"])
|
||||
|
||||
def unpack_image(self, entry, imgmountdir):
|
||||
"""
|
||||
|
||||
:param entry:
|
||||
:param imgmountdir:
|
||||
:return:
|
||||
"""
|
||||
|
||||
def progress_cb(copied):
|
||||
"""
|
||||
|
||||
:param copied:
|
||||
"""
|
||||
entry.copied = copied
|
||||
self.report_progress()
|
||||
|
||||
@ -196,6 +243,11 @@ def run():
|
||||
# sourcefs: "squashfs"
|
||||
# destination: ""
|
||||
|
||||
"""
|
||||
|
||||
|
||||
:return:
|
||||
"""
|
||||
PATH_PROCFS = '/proc/filesystems'
|
||||
|
||||
root_mount_point = globalstorage.value("rootMountPoint")
|
||||
|
Loading…
Reference in New Issue
Block a user