PEPify mount

This commit is contained in:
Teo Mrnjavac 2014-07-29 14:45:58 +02:00
parent 585dd20a34
commit 2ba96d3b6b

View File

@ -19,19 +19,18 @@
import os import os
import subprocess import subprocess
import sys
import tempfile import tempfile
import libcalamares import libcalamares
# FIXME: Duplicated between mount and grub # FIXME: Duplicated between mount and grub
def mount( devicePath, mountPoint, fs = None, options = None ): def mount(device_path, mount_point, fs=None, options=None):
assert devicePath assert device_path
assert mountPoint assert mount_point
if not os.path.exists( mountPoint ): if not os.path.exists(mount_point):
os.makedirs( mountPoint ) os.makedirs(mount_point)
cmd = [ "mount", devicePath, mountPoint ] cmd = ["mount", device_path, mount_point]
if fs: if fs:
cmd += ("-t", fs) cmd += ("-t", fs)
if options: if options:
@ -39,26 +38,27 @@ def mount( devicePath, mountPoint, fs = None, options = None ):
subprocess.check_call(cmd) subprocess.check_call(cmd)
def mountPartitions( rootMountPoint, partitions ): def mount_partitions(root_mount_point, partitions):
for partition in partitions: for partition in partitions:
if not partition["mountPoint"]: if not partition["mountPoint"]:
continue continue
# 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 '/'.
mountPoint = rootMountPoint + partition[ "mountPoint" ] mount_point = root_mount_point + partition["mountPoint"]
mount( partition[ "device" ], mountPoint, mount(partition["device"], mount_point,
fs=partition.get("fs"), fs=partition.get("fs"),
options=partition.get("options") options=partition.get("options")
) )
def run(): def run():
rootMountPoint = tempfile.mkdtemp( prefix="calamares-root-" ) root_mount_point = tempfile.mkdtemp(prefix="calamares-root-")
partitions = libcalamares.globalStorage.value( "partitions" ) partitions = libcalamares.globalstorage.value("partitions")
# 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"])
mountPartitions( rootMountPoint, libcalamares.globalStorage.value( "partitions" ) ) mount_partitions(
root_mount_point, libcalamares.globalstorage.value("partitions"))
libcalamares.globalStorage.insert( "rootMountPoint", rootMountPoint ) libcalamares.globalstorage.insert("rootMountPoint", root_mount_point)
return None return None