From 545eef57611782b768553c2b78a0c9b1e5be4c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 24 Jul 2014 17:14:56 +0200 Subject: [PATCH] Refactor mount module to make its code easier to reuse --- src/modules/mount/main.py | 40 ++++++++++++++++++++++------------- src/modules/mount/module.conf | 3 --- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 1f3ee1f4c..9d30823fb 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -24,31 +24,41 @@ import tempfile import libcalamares -def mount( devicePath, mountPoint, fs ): - if not os.path.exists( mountPoint ): - os.makedirs( mountPoint ) + +# FIXME: Duplicated between mount and grub +def mount( devicePath, mountPoint, fs = None, options = None ): assert devicePath assert mountPoint - assert fs - subprocess.check_call( [ "mount", "-t", fs, devicePath, mountPoint ] ) + if not os.path.exists( mountPoint ): + os.makedirs( mountPoint ) + cmd = [ "mount", devicePath, mountPoint ] + if fs: + cmd += ( "-t", fs ) + if options: + cmd += ( "-o", options ) + subprocess.check_call( cmd ) def mountPartitions( rootMountPoint, partitions ): - lst = [ x for x in partitions if x[ "mountPoint" ] == "/" ] - assert lst, "No root partition found" - root = lst[ 0 ] - - mount( root[ "device" ], rootMountPoint, root[ "fs" ] ) - for partition in partitions: - # Skip / and partitions which have no mount points - if partition[ "mountPoint" ] in ( "/", "" ): + if not partition[ "mountPoint" ]: continue - mount( partition[ "device" ], rootMountPoint + partition[ "mountPoint" ], partition[ "fs" ]) + # Create mount point with `+` rather than `os.path.join()` because + # `mountPoint` starts with a '/'. + mountPoint = rootMountPoint + partition[ "mountPoint" ] + mount( partition[ "device" ], mountPoint, + fs = partition.get( "fs" ), + options = partition.get( "options" ) + ) def calamares_main(): rootMountPoint = tempfile.mkdtemp( prefix="calamares-root-" ) + partitions = libcalamares.global_storage.value( "partitions" ) + + # Sort by mount points to ensure / is mounted before the rest + partitions.sort( key = lambda x: x[ "mountPoint" ] ) mountPartitions( rootMountPoint, libcalamares.global_storage.value( "partitions" ) ) + libcalamares.global_storage.insert( "rootMountPoint", rootMountPoint ) - return "all done, mounted at {}".format( rootMountPoint ) + return "All done, mounted at {}".format( rootMountPoint ) diff --git a/src/modules/mount/module.conf b/src/modules/mount/module.conf index 21d6d0bcb..560e3087a 100644 --- a/src/modules/mount/module.conf +++ b/src/modules/mount/module.conf @@ -1,6 +1,3 @@ -# Module metadata file for dummy process jobmodule -# Syntax is YAML 1.2 ---- type: "job" name: "mount" interface: "python"