Merge pull request #225 from Gormogon/master

Last PEP Cleanup
main
Teo Mrnjavac 10 years ago
commit f080e3cced

@ -215,7 +215,7 @@ def prepare_bootloader(fw_type):
boot_p = boot_device[-1:] boot_p = boot_device[-1:]
device = boot_device[:-1] device = boot_device[:-1]
if (not boot_p or not device): if not boot_p or not device:
return ("EFI directory \"{!s}\" not found!", return ("EFI directory \"{!s}\" not found!",
"Boot partition: \"{!s}\"", "Boot partition: \"{!s}\"",
"Boot device: \"{!s}\"".format(efi_directory, boot_p, device)) "Boot device: \"{!s}\"".format(efi_directory, boot_p, device))

@ -56,9 +56,11 @@ def is_ssd_disk(disk_name):
:return: :return:
""" """
filename = os.path.join("/sys/block", disk_name, "queue/rotational") filename = os.path.join("/sys/block", disk_name, "queue/rotational")
if not os.path.exists(filename): if not os.path.exists(filename):
# Should not happen unless sysfs changes, but better safe than sorry # Should not happen unless sysfs changes, but better safe than sorry
return False return False
with open(filename) as f: with open(filename) as f:
return f.read() == "0\n" return f.read() == "0\n"
@ -70,8 +72,10 @@ def disk_name_for_partition(partition):
:return: :return:
""" """
name = os.path.basename(partition["device"]) name = os.path.basename(partition["device"])
if name.startswith("/dev/mmcblk"): if name.startswith("/dev/mmcblk"):
return re.sub("p[0-9]+$", "", name) return re.sub("p[0-9]+$", "", name)
return re.sub("[0-9]+$", "", name) return re.sub("[0-9]+$", "", name)
@ -83,9 +87,7 @@ class FstabGenerator(object):
:param mount_options: :param mount_options:
:param ssd_extra_mount_options: :param ssd_extra_mount_options:
""" """
def __init__(self, partitions, root_mount_point, mount_options, ssd_extra_mount_options):
def __init__(self, partitions, root_mount_point, mount_options,
ssd_extra_mount_options):
self.partitions = partitions self.partitions = partitions
self.root_mount_point = root_mount_point self.root_mount_point = root_mount_point
self.mount_options = mount_options self.mount_options = mount_options
@ -101,6 +103,7 @@ class FstabGenerator(object):
self.find_ssd_disks() self.find_ssd_disks()
self.generate_fstab() self.generate_fstab()
self.create_mount_points() self.create_mount_points()
return None return None
def find_ssd_disks(self): def find_ssd_disks(self):
@ -112,22 +115,24 @@ class FstabGenerator(object):
""" Create fstab. """ """ Create fstab. """
mkdir_p(os.path.join(self.root_mount_point, "etc")) mkdir_p(os.path.join(self.root_mount_point, "etc"))
fstab_path = os.path.join(self.root_mount_point, "etc", "fstab") fstab_path = os.path.join(self.root_mount_point, "etc", "fstab")
with open(fstab_path, "w") as fl: with open(fstab_path, "w") as fl:
print(HEADER, file=fl) print(HEADER, file=fl)
for partition in self.partitions: for partition in self.partitions:
dct = self.generate_fstab_line_info(partition) dct = self.generate_fstab_line_info(partition)
if dct: if dct:
self.print_fstab_line(dct, file=fl) self.print_fstab_line(dct, file=fl)
if self.root_is_ssd: if self.root_is_ssd:
# Mount /tmp on a tmpfs # Mount /tmp on a tmpfs
dct = dict( dct = dict(device="tmpfs",
device="tmpfs", mount_point="/tmp",
mount_point="/tmp", fs="tmpfs",
fs="tmpfs", options="defaults,noatime,mode=1777",
options="defaults,noatime,mode=1777", check=0,
check=0, )
)
self.print_fstab_line(dct, file=fl) self.print_fstab_line(dct, file=fl)
def generate_fstab_line_info(self, partition): def generate_fstab_line_info(self, partition):
@ -140,7 +145,6 @@ class FstabGenerator(object):
mount_point = partition["mountPoint"] mount_point = partition["mountPoint"]
disk_name = disk_name_for_partition(partition) disk_name = disk_name_for_partition(partition)
is_ssd = disk_name in self.ssd_disks is_ssd = disk_name in self.ssd_disks
fs = FS_MAP.get(fs, fs) fs = FS_MAP.get(fs, fs)
if not mount_point and not fs == "swap": if not mount_point and not fs == "swap":
@ -149,6 +153,7 @@ class FstabGenerator(object):
options = self.mount_options.get(fs, self.mount_options["default"]) options = self.mount_options.get(fs, self.mount_options["default"])
if is_ssd: if is_ssd:
extra = self.ssd_extra_mount_options.get(fs) extra = self.ssd_extra_mount_options.get(fs)
if extra: if extra:
options += "," + extra options += "," + extra
@ -162,12 +167,12 @@ class FstabGenerator(object):
if mount_point == "/": if mount_point == "/":
self.root_is_ssd = is_ssd self.root_is_ssd = is_ssd
return dict( return dict(device="UUID=" + partition["uuid"],
device="UUID=" + partition["uuid"], mount_point=mount_point or "swap",
mount_point=mount_point or "swap", fs=fs,
fs=fs, options=options,
options=options, check=check,
check=check) )
def print_fstab_line(self, dct, file=None): def print_fstab_line(self, dct, file=None):
""" Prints line to '/etc/fstab' file. """ Prints line to '/etc/fstab' file.
@ -175,12 +180,12 @@ class FstabGenerator(object):
:param dct: :param dct:
:param file: :param file:
""" """
line = "{:41} {:<14} {:<7} {:<10} 0 {}".format( line = "{:41} {:<14} {:<7} {:<10} 0 {}".format(dct["device"],
dct["device"], dct["mount_point"],
dct["mount_point"], dct["fs"],
dct["fs"], dct["options"],
dct["options"], dct["check"],
dct["check"]) )
print(line, file=file) print(line, file=file)
def create_mount_points(self): def create_mount_points(self):
@ -199,10 +204,8 @@ def run():
conf = libcalamares.job.configuration conf = libcalamares.job.configuration
partitions = gs.value("partitions") partitions = gs.value("partitions")
root_mount_point = gs.value("rootMountPoint") root_mount_point = gs.value("rootMountPoint")
mount_options = conf["mountOptions"] mount_options = conf["mountOptions"]
ssd_extra_mount_options = conf.get("ssdExtraMountOptions", {}) ssd_extra_mount_options = conf.get("ssdExtraMountOptions", {})
generator = FstabGenerator(partitions, root_mount_point, mount_options, ssd_extra_mount_options)
generator = FstabGenerator(partitions, root_mount_point,
mount_options, ssd_extra_mount_options)
return generator.run() return generator.run()

@ -49,8 +49,10 @@ def modify_grub_default(partitions, root_mount_point, distributor):
swap_uuid = partition["uuid"] swap_uuid = partition["uuid"]
kernel_params = ["quiet"] kernel_params = ["quiet"]
if use_splash: if use_splash:
kernel_params.append(use_splash) kernel_params.append(use_splash)
if swap_uuid: if swap_uuid:
kernel_params.append("resume=UUID={!s}".format(swap_uuid)) kernel_params.append("resume=UUID={!s}".format(swap_uuid))
@ -89,6 +91,7 @@ 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 if existing_param_name not in ["quiet", "resume", "splash"]: # the only ones we ever add
kernel_params.append(existing_param) kernel_params.append(existing_param)
@ -100,6 +103,7 @@ def modify_grub_default(partitions, root_mount_point, distributor):
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":
@ -109,6 +113,7 @@ def modify_grub_default(partitions, root_mount_point, distributor):
escaped_value = "false" escaped_value = "false"
else: else:
escaped_value = str(value).replace("'", "'\\''") escaped_value = str(value).replace("'", "'\\''")
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:
@ -133,4 +138,5 @@ def run():
root_mount_point = libcalamares.globalstorage.value("rootMountPoint") root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
branding = libcalamares.globalstorage.value("branding") branding = libcalamares.globalstorage.value("branding")
distributor = branding["bootloaderEntryName"] distributor = branding["bootloaderEntryName"]
return modify_grub_default(partitions, root_mount_point, distributor) return modify_grub_default(partitions, root_mount_point, distributor)

@ -32,8 +32,7 @@ def run():
try: try:
subprocess.check_call(["hwclock", "--systohc", "--utc"]) subprocess.check_call(["hwclock", "--systohc", "--utc"])
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
return "Cannot set hardware clock.", \ return "Cannot set hardware clock.", "hwclock terminated with exit code {}.".format(e.returncode)
"hwclock terminated with exit code {}.".format(e.returncode)
shutil.copy2("/etc/adjtime", "{!s}/etc/".format(root_mount_point)) shutil.copy2("/etc/adjtime", "{!s}/etc/".format(root_mount_point))

@ -34,4 +34,5 @@ def run():
:return: :return:
""" """
run_mkinitcpio() run_mkinitcpio()
return None return None

@ -31,15 +31,16 @@ def cpuinfo():
cpu_info['proc0']={...} cpu_info['proc0']={...}
cpu_info['proc1']={...} cpu_info['proc1']={...}
""" """
cpuinfo = OrderedDict() cpu_info = OrderedDict()
procinfo = OrderedDict() procinfo = OrderedDict()
nprocs = 0 nprocs = 0
with open('/proc/cpuinfo') as f: with open('/proc/cpuinfo') as f:
for line in f: for line in f:
if not line.strip(): if not line.strip():
# end of one processor # end of one processor
cpuinfo["proc{!s}".format(nprocs)] = procinfo cpu_info["proc{!s}".format(nprocs)] = procinfo
nprocs += 1 nprocs += 1
# Reset # Reset
procinfo = OrderedDict() procinfo = OrderedDict()
@ -49,7 +50,7 @@ def cpuinfo():
else: else:
procinfo[line.split(':')[0].strip()] = '' procinfo[line.split(':')[0].strip()] = ''
return cpuinfo return cpu_info
def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point): def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
@ -71,6 +72,7 @@ def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
mklins[i] = "MODULES=\"{!s}\"".format(joined_modules) mklins[i] = "MODULES=\"{!s}\"".format(joined_modules)
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf") path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
with open(path, "w") as mkinitcpio_file: with open(path, "w") as mkinitcpio_file:
mkinitcpio_file.write("\n".join(mklins) + "\n") mkinitcpio_file.write("\n".join(mklins) + "\n")
@ -95,6 +97,7 @@ def modify_mkinitcpio_conf(partitions, root_mount_point):
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["fs"] == "btrfs": if partition["fs"] == "btrfs":
btrfs = "yes" btrfs = "yes"
@ -121,4 +124,5 @@ def run():
partitions = libcalamares.globalstorage.value("partitions") partitions = libcalamares.globalstorage.value("partitions")
root_mount_point = libcalamares.globalstorage.value("rootMountPoint") root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
modify_mkinitcpio_conf(partitions, root_mount_point) modify_mkinitcpio_conf(partitions, root_mount_point)
return None return None

@ -26,6 +26,7 @@ def run():
:return: :return:
""" """
returnCode = chroot_call(["update-initramfs", "-k", "all", "-u"]) return_code = 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)) if return_code != 0:
return "Failed to run update-initramfs on the target", "The exit code was {}".format(return_code)

@ -27,9 +27,9 @@ import libcalamares
def run(): def run():
""" Create locale """ """ Create locale """
us = '#en_US' us = '#en_US'
locale = libcalamares.globalstorage.value("lcLocale") locale = libcalamares.globalstorage.value("lcLocale")
if not locale: if not locale:
locale = 'en_US.UTF-8 UTF-8' locale = 'en_US.UTF-8 UTF-8'
@ -43,6 +43,7 @@ def run():
# run locale-gen if detected # run locale-gen if detected
if os.path.exists('/etc/locale.gen'): if os.path.exists('/etc/locale.gen'):
text = [] text = []
with open("{!s}/etc/locale.gen".format(install_path), "r") as gen: with open("{!s}/etc/locale.gen".format(install_path), "r") as gen:
text = gen.readlines() text = gen.readlines()
@ -52,15 +53,18 @@ def run():
if us in line and line[0] == "#": if us in line and line[0] == "#":
# uncomment line # uncomment line
line = line[1:] line = line[1:]
if locale in line and line[0] == "#": if locale in line and line[0] == "#":
# uncomment line # uncomment line
line = line[1:] line = line[1:]
gen.write(line) gen.write(line)
libcalamares.utils.chroot_call(['locale-gen']) libcalamares.utils.chroot_call(['locale-gen'])
print('locale.gen done') print('locale.gen done')
locale_conf_path = os.path.join(install_path, "etc/locale.conf") locale_conf_path = os.path.join(install_path, "etc/locale.conf")
with open(locale_conf_path, "w") as locale_conf: with open(locale_conf_path, "w") as locale_conf:
locale_split = locale.split(' ')[0] locale_split = locale.split(' ')[0]
locale_conf.write("LANG={!s}\n".format(locale_split)) locale_conf.write("LANG={!s}\n".format(locale_split))

@ -33,16 +33,22 @@ def run():
enable_dbus = libcalamares.job.configuration["dbus"] enable_dbus = libcalamares.job.configuration["dbus"]
enable_symlink = libcalamares.job.configuration["symlink"] enable_symlink = libcalamares.job.configuration["symlink"]
target_systemd_machineid_file = "{}/etc/machine-id".format(root_mount_point) target_systemd_machineid_file = "{}/etc/machine-id".format(root_mount_point)
if enable_systemd: if enable_systemd:
if os.path.exists(target_systemd_machineid_file): if os.path.exists(target_systemd_machineid_file):
os.remove(target_systemd_machineid_file) os.remove(target_systemd_machineid_file)
check_chroot_call("systemd-machine-id-setup") check_chroot_call("systemd-machine-id-setup")
if enable_dbus: if enable_dbus:
target_dbus_machineid_file = "{}/var/lib/dbus/machine-id".format(root_mount_point) target_dbus_machineid_file = "{}/var/lib/dbus/machine-id".format(root_mount_point)
if os.path.exists(target_dbus_machineid_file): if os.path.exists(target_dbus_machineid_file):
os.remove(target_dbus_machineid_file) os.remove(target_dbus_machineid_file)
if enable_symlink and os.path.exists(target_systemd_machineid_file): if enable_symlink and os.path.exists(target_systemd_machineid_file):
check_chroot_call(["ln", "-s", "/etc/machine-id", "/var/lib/dbus/machine-id"]) check_chroot_call(["ln", "-s", "/etc/machine-id", "/var/lib/dbus/machine-id"])
else: else:
check_chroot_call(["dbus-uuidgen", "--ensure"]) check_chroot_call(["dbus-uuidgen", "--ensure"])
return None return None

@ -35,17 +35,16 @@ def mount_partitions(root_mount_point, partitions):
# Create mount point with `+` rather than `os.path.join()` because # Create mount point with `+` rather than `os.path.join()` because
# `partition["mountPoint"]` starts with a '/'. # `partition["mountPoint"]` starts with a '/'.
mount_point = root_mount_point + partition["mountPoint"] mount_point = root_mount_point + partition["mountPoint"]
fstype = partition.get("fs", "") fstype = partition.get("fs", "")
if fstype == "fat16" or fstype == "fat32": if fstype == "fat16" or fstype == "fat32":
fstype = "vfat" fstype = "vfat"
libcalamares.utils.mount( libcalamares.utils.mount(partition["device"],
partition["device"], mount_point,
mount_point, fstype,
fstype, partition.get("options", ""),
partition.get("options", "") )
)
def run(): def run():
@ -61,14 +60,14 @@ def run():
# Sort by mount points to ensure / is mounted before the rest # Sort by mount points to ensure / is mounted before the rest
partitions.sort(key=lambda x: x["mountPoint"]) partitions.sort(key=lambda x: x["mountPoint"])
mount_partitions(root_mount_point, partitions) mount_partitions(root_mount_point, partitions)
mount_partitions(root_mount_point, extra_mounts) mount_partitions(root_mount_point, extra_mounts)
fw_type = libcalamares.globalstorage.value("firmwareType") fw_type = libcalamares.globalstorage.value("firmwareType")
if fw_type == 'efi': if fw_type == 'efi':
mount_partitions(root_mount_point, extra_mounts_efi) mount_partitions(root_mount_point, extra_mounts_efi)
libcalamares.globalstorage.insert("rootMountPoint", root_mount_point) libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
# Remember the extra mounts for the unpackfs module # Remember the extra mounts for the unpackfs module
if fw_type == 'efi': if fw_type == 'efi':
libcalamares.globalstorage.insert("extraMounts", extra_mounts + extra_mounts_efi) libcalamares.globalstorage.insert("extraMounts", extra_mounts + extra_mounts_efi)

@ -30,8 +30,7 @@ def run():
root_mount_point = libcalamares.globalstorage.value("rootMountPoint") root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
source_nm = "/etc/NetworkManager/system-connections/" source_nm = "/etc/NetworkManager/system-connections/"
target_nm = os.path.join(root_mount_point, target_nm = os.path.join(root_mount_point, "etc/NetworkManager/system-connections/")
"etc/NetworkManager/system-connections/")
# Sanity checks. We don't want to do anything if a network # Sanity checks. We don't want to do anything if a network
# configuration already exists on the target # configuration already exists on the target
@ -50,8 +49,7 @@ def run():
try: try:
shutil.copy(source_network, target_network) shutil.copy(source_network, target_network)
except FileNotFoundError: except FileNotFoundError:
libcalamares.utils.debug( libcalamares.utils.debug("Can't copy network configuration files in {}".format(source_network))
"Can't copy network configuration files in {}".format(source_network))
except FileExistsError: except FileExistsError:
pass pass

@ -34,26 +34,29 @@ class PackageManager:
""" Installs packages. """ Installs packages.
:param pkgs: :param pkgs:
:param from_local:
""" """
if self.backend == "packagekit": if self.backend == "packagekit":
for pkg in pkgs: for pkg in pkgs:
check_chroot_call(["pkcon", "-py", "install", pkg]) check_chroot_call(["pkcon", "-py", "install", pkg])
elif self.backend == "zypp": elif self.backend == "zypp":
check_chroot_call( check_chroot_call(["zypper", "--non-interactive", "--quiet-install", "install",
["zypper", "--non-interactive", "--quiet-install", "install", "--auto-agree-with-licenses", "install"] + pkgs)
"--auto-agree-with-licenses", "install"] + pkgs)
elif self.backend == "yum": elif self.backend == "yum":
check_chroot_call(["yum", "install", "-y"] + pkgs) check_chroot_call(["yum", "install", "-y"] + pkgs)
elif self.backend == "dnf": elif self.backend == "dnf":
check_chroot_call(["dnf", "install", "-y"] + pkgs) check_chroot_call(["dnf", "install", "-y"] + pkgs)
elif self.backend == "urpmi": elif self.backend == "urpmi":
check_chroot_call( check_chroot_call(["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm",
["urpmi", "--download-all", "--no-suggests", "--no-verify-rpm", "--fastunsafe", "--ignoresize", "--nolock", "--auto"] + pkgs)
"--fastunsafe", "--ignoresize", "--nolock", "--auto"] + pkgs)
elif self.backend == "apt": elif self.backend == "apt":
check_chroot_call(["apt-get", "-q", "-y", "install"] + pkgs) check_chroot_call(["apt-get", "-q", "-y", "install"] + pkgs)
elif self.backend == "pacman": elif self.backend == "pacman":
pacman_flags = "-U" if from_local else "-Sy" if from_local:
pacman_flags = "-U"
else:
pacman_flags = "-Sy"
check_chroot_call(["pacman", pacman_flags, "--noconfirm"] + pkgs) check_chroot_call(["pacman", pacman_flags, "--noconfirm"] + pkgs)
elif self.backend == "portage": elif self.backend == "portage":
check_chroot_call(["emerge", "-v"] + pkgs) check_chroot_call(["emerge", "-v"] + pkgs)
@ -110,17 +113,19 @@ def run():
:return: :return:
""" """
backend = libcalamares.job.configuration.get("backend") backend = libcalamares.job.configuration.get("backend")
if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman", "portage", "entropy"): if backend not in ("packagekit", "zypp", "yum", "dnf", "urpmi", "apt", "pacman", "portage", "entropy"):
return ("Bad backend", "backend=\"{}\"".format(backend)) return "Bad backend", "backend=\"{}\"".format(backend)
pkgman = PackageManager(backend) pkgman = PackageManager(backend)
operations = libcalamares.job.configuration.get("operations", []) operations = libcalamares.job.configuration.get("operations", [])
for entry in operations: for entry in operations:
run_operations(pkgman, entry) run_operations(pkgman, entry)
if libcalamares.globalstorage.contains("packageOperations"): if libcalamares.globalstorage.contains("packageOperations"):
operations = libcalamares.globalstorage.value("packageOperations") operations = libcalamares.globalstorage.value("packageOperations")
for entry in operations: for entry in operations:
run_operations(pkgman, entry) run_operations(pkgman, entry)

@ -24,12 +24,11 @@ import libcalamares
def run(): def run():
""" Remove live user from target system """ """ Remove live user from target system """
username = libcalamares.job.configuration["username"]
username = libcalamares.job.configuration[("username")]
try: try:
libcalamares.utils.check_chroot_call(["userdel", "-f", "-r", username]) libcalamares.utils.check_chroot_call(["userdel", "-f", "-r", username])
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
libcalamares.utils.debug( "Cannot remove user. " + libcalamares.utils.debug("Cannot remove user.", "'userdel' terminated with exit code {}.".format(e.returncode))
"userdel terminated with exit code {}.".format(e.returncode))
return None return None

@ -24,38 +24,31 @@ import libcalamares
def run(): def run():
""" Setup systemd services """ """ Setup systemd services """
services = libcalamares.job.configuration['services'] services = libcalamares.job.configuration['services']
targets = libcalamares.job.configuration['targets'] targets = libcalamares.job.configuration['targets']
# enable services # enable services
for svc in services: for svc in services:
ec = libcalamares.utils.chroot_call(['systemctl', ec = libcalamares.utils.chroot_call(['systemctl', 'enable', '{}.service'.format(svc['name'])])
'enable',
'{}.service'.format(svc['name'])])
if ec != 0: if ec != 0:
if svc['mandatory']: if svc['mandatory']:
return "Cannot enable systemd service {}".format(svc['name']), \ return "Cannot enable systemd service {}".format(svc['name']), \
"systemctl enable call in chroot returned error code {}".format(ec) "systemctl enable call in chroot returned error code {}".format(ec)
else: else:
libcalamares.utils.debug( libcalamares.utils.debug("Cannot enable systemd service {}".format(svc['name']))
"Cannot enable systemd service {}".format(svc['name'])) libcalamares.utils.debug("systemctl enable call in chroot returned error code {}".format(ec))
libcalamares.utils.debug(
"systemctl enable call in chroot returned error code {}".format(ec))
# enable targets # enable targets
for tgt in targets: for tgt in targets:
ec = libcalamares.utils.chroot_call(['systemctl', ec = libcalamares.utils.chroot_call(['systemctl', 'enable', '{}.target'.format(tgt['name'])])
'enable',
'{}.target'.format(tgt['name'])])
if ec != 0: if ec != 0:
if tgt['mandatory']: if tgt['mandatory']:
return "Cannot enable systemd target {}".format(tgt['name']), \ return "Cannot enable systemd target {}".format(tgt['name']), \
"systemctl enable call in chroot returned error code {}".format(ec) "systemctl enable call in chroot returned error code {}".format(ec)
else: else:
libcalamares.utils.debug( libcalamares.utils.debug("Cannot enable systemd target {}".format(tgt['name']))
"Cannot enable systemd target {}".format(tgt['name'])) libcalamares.utils.debug("systemctl enable call in chroot returned error code {}".format(ec))
libcalamares.utils.debug(
"systemctl enable call in chroot returned error code {}".format(ec))
return None return None

@ -31,10 +31,13 @@ def list_mounts(root_mount_point):
:return: :return:
""" """
lst = [] lst = []
for line in open("/etc/mtab").readlines(): for line in open("/etc/mtab").readlines():
device, mount_point, _ = line.split(" ", 2) device, mount_point, _ = line.split(" ", 2)
if mount_point.startswith(root_mount_point): if mount_point.startswith(root_mount_point):
lst.append((device, mount_point)) lst.append((device, mount_point))
return lst return lst
@ -44,10 +47,12 @@ def run():
:return: :return:
""" """
root_mount_point = libcalamares.globalstorage.value("rootMountPoint") root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
if not root_mount_point: if not root_mount_point:
return ("No mount point for root partition in globalstorage", return ("No mount point for root partition in globalstorage",
"globalstorage does not contain a \"rootMountPoint\" key, " "globalstorage does not contain a \"rootMountPoint\" key, "
"doing nothing") "doing nothing")
if not os.path.exists(root_mount_point): if not os.path.exists(root_mount_point):
return ("Bad mount point for root partition in globalstorage", return ("Bad mount point for root partition in globalstorage",
"globalstorage[\"rootMountPoint\"] is \"{}\", which does not " "globalstorage[\"rootMountPoint\"] is \"{}\", which does not "
@ -62,4 +67,5 @@ def run():
subprocess.check_call(["umount", "-lv", mount_point]) subprocess.check_call(["umount", "-lv", mount_point])
os.rmdir(root_mount_point) os.rmdir(root_mount_point)
return None return None

@ -26,7 +26,6 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from collections import namedtuple
from libcalamares import * from libcalamares import *
@ -59,10 +58,13 @@ def list_excludes(destination):
""" """
lst = [] lst = []
extra_mounts = globalstorage.value("extraMounts") extra_mounts = globalstorage.value("extraMounts")
for extra_mount in extra_mounts: for extra_mount in extra_mounts:
mount_point = extra_mount["mountPoint"] mount_point = extra_mount["mountPoint"]
if mount_point: if mount_point:
lst.extend(['--exclude', mount_point + '/']) lst.extend(['--exclude', mount_point + '/'])
return lst return lst
@ -87,11 +89,7 @@ def file_copy(source, dest, progress_cb):
args = ['rsync', '-aHAXr'] args = ['rsync', '-aHAXr']
args.extend(list_excludes(dest)) args.extend(list_excludes(dest))
args.extend(['--progress', source, dest]) args.extend(['--progress', source, dest])
process = subprocess.Popen(args, process = subprocess.Popen(args, env=at_env, bufsize=1, stdout=subprocess.PIPE, close_fds=ON_POSIX)
env=at_env,
bufsize=1,
stdout=subprocess.PIPE,
close_fds=ON_POSIX)
for line in iter(process.stdout.readline, b''): for line in iter(process.stdout.readline, b''):
# small comment on this regexp. # small comment on this regexp.
@ -107,6 +105,7 @@ def file_copy(source, dest, progress_cb):
# therefore we can easily subtract x from y in order to get real files # therefore we can easily subtract x from y in order to get real files
# copied / processed count. # copied / processed count.
m = re.findall(r'xfr#(\d+), ir-chk=(\d+)/(\d+)', line.decode()) m = re.findall(r'xfr#(\d+), ir-chk=(\d+)/(\d+)', line.decode())
if m: if m:
# we've got a percentage update # we've got a percentage update
num_files_remaining = int(m[0][1]) num_files_remaining = int(m[0][1])
@ -117,9 +116,12 @@ def file_copy(source, dest, progress_cb):
# I guess we're updating every 100 files... # I guess we're updating every 100 files...
if num_files_copied % 100 == 0: if num_files_copied % 100 == 0:
progress_cb(num_files_copied) progress_cb(num_files_copied)
process.wait() process.wait()
if process.returncode != 0: if process.returncode != 0:
return "rsync failed with error code {}.".format(process.returncode) return "rsync failed with error code {}.".format(process.returncode)
return None return None
@ -128,6 +130,7 @@ class UnpackOperation:
:param entries: :param entries:
""" """
def __init__(self, entries): def __init__(self, entries):
self.entries = entries self.entries = entries
self.entry_for_source = dict((x.source, x) for x in self.entries) self.entry_for_source = dict((x.source, x) for x in self.entries)
@ -135,6 +138,7 @@ class UnpackOperation:
def report_progress(self): def report_progress(self):
""" Pass progress to user interface """ """ Pass progress to user interface """
progress = float(0) progress = float(0)
for entry in self.entries: for entry in self.entries:
if entry.total == 0: if entry.total == 0:
continue continue
@ -152,10 +156,10 @@ class UnpackOperation:
:return: :return:
""" """
source_mount_path = tempfile.mkdtemp() source_mount_path = tempfile.mkdtemp()
try: try:
for entry in self.entries: for entry in self.entries:
imgbasename = os.path.splitext( imgbasename = os.path.splitext(os.path.basename(entry.source))[0]
os.path.basename(entry.source))[0]
imgmountdir = os.path.join(source_mount_path, imgbasename) imgmountdir = os.path.join(source_mount_path, imgbasename)
os.mkdir(imgmountdir) os.mkdir(imgmountdir)
@ -169,20 +173,19 @@ class UnpackOperation:
"Failed to find unsquashfs, make sure you have " "Failed to find unsquashfs, make sure you have "
"the squashfs-tools package installed") "the squashfs-tools package installed")
fslist = subprocess.check_output(["unsquashfs", fslist = subprocess.check_output(["unsquashfs", "-l", entry.source])
"-l",
entry.source])
if entry.sourcefs == "ext4": if entry.sourcefs == "ext4":
fslist = subprocess.check_output(["find", fslist = subprocess.check_output(["find", imgmountdir, "-type", "f"])
imgmountdir,
"-type", "f"])
entry.total = len(fslist.splitlines()) entry.total = len(fslist.splitlines())
self.report_progress() self.report_progress()
error_msg = self.unpack_image(entry, imgmountdir) error_msg = self.unpack_image(entry, imgmountdir)
if error_msg: if error_msg:
return ("Failed to unpack image {}".format(entry.source), return "Failed to unpack image {}".format(entry.source), error_msg
error_msg)
return None return None
finally: finally:
shutil.rmtree(source_mount_path) shutil.rmtree(source_mount_path)
@ -193,12 +196,7 @@ class UnpackOperation:
:param entry: :param entry:
:param imgmountdir: :param imgmountdir:
""" """
subprocess.check_call(["mount", subprocess.check_call(["mount", entry.source, imgmountdir, "-t", entry.sourcefs, "-o", "loop"])
entry.source,
imgmountdir,
"-t",
entry.sourcefs,
"-o", "loop"])
def unpack_image(self, entry, imgmountdir): def unpack_image(self, entry, imgmountdir):
""" Unpacks image. """ Unpacks image.
@ -207,7 +205,6 @@ class UnpackOperation:
:param imgmountdir: :param imgmountdir:
:return: :return:
""" """
def progress_cb(copied): def progress_cb(copied):
""" Copies file to given destination target. """ Copies file to given destination target.
@ -217,9 +214,7 @@ class UnpackOperation:
self.report_progress() self.report_progress()
try: try:
return file_copy(imgmountdir, return file_copy(imgmountdir, entry.destination, progress_cb)
entry.destination,
progress_cb)
finally: finally:
subprocess.check_call(["umount", "-l", imgmountdir]) subprocess.check_call(["umount", "-l", imgmountdir])
@ -245,14 +240,17 @@ def run():
PATH_PROCFS = '/proc/filesystems' PATH_PROCFS = '/proc/filesystems'
root_mount_point = globalstorage.value("rootMountPoint") root_mount_point = globalstorage.value("rootMountPoint")
if not root_mount_point: if not root_mount_point:
return ("No mount point for root partition in globalstorage", return ("No mount point for root partition in globalstorage",
"globalstorage does not contain a \"rootMountPoint\" key, " "globalstorage does not contain a \"rootMountPoint\" key, "
"doing nothing") "doing nothing")
if not os.path.exists(root_mount_point): if not os.path.exists(root_mount_point):
return ("Bad mount point for root partition in globalstorage", return ("Bad mount point for root partition in globalstorage",
"globalstorage[\"rootMountPoint\"] is \"{}\", which does not " "globalstorage[\"rootMountPoint\"] is \"{}\", which does not "
"exist, doing nothing".format(root_mount_point)) "exist, doing nothing".format(root_mount_point))
unpack = list() unpack = list()
for entry in job.configuration["unpack"]: for entry in job.configuration["unpack"]:
@ -279,12 +277,13 @@ def run():
destination = os.path.abspath(root_mount_point + entry["destination"]) destination = os.path.abspath(root_mount_point + entry["destination"])
if not os.path.exists(source) or os.path.isdir(source): if not os.path.exists(source) or os.path.isdir(source):
return ("Bad source", "source=\"{}\"".format(source)) return "Bad source", "source=\"{}\"".format(source)
if not os.path.isdir(destination): if not os.path.isdir(destination):
return ("Bad destination", return "Bad destination", "destination=\"{}\"".format(destination)
"destination=\"{}\"".format(destination))
unpack.append(UnpackEntry(source, sourcefs, destination)) unpack.append(UnpackEntry(source, sourcefs, destination))
unpackop = UnpackOperation(unpack) unpackop = UnpackOperation(unpack)
return unpackop.run() return unpackop.run()

Loading…
Cancel
Save