Refactor mount module to make its code easier to reuse

main
Aurélien Gâteau 11 years ago
parent 96ede98f27
commit 545eef5761

@ -24,31 +24,41 @@ import tempfile
import libcalamares import libcalamares
def mount( devicePath, mountPoint, fs ):
if not os.path.exists( mountPoint ): # FIXME: Duplicated between mount and grub
os.makedirs( mountPoint ) def mount( devicePath, mountPoint, fs = None, options = None ):
assert devicePath assert devicePath
assert mountPoint assert mountPoint
assert fs if not os.path.exists( mountPoint ):
subprocess.check_call( [ "mount", "-t", fs, devicePath, 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 ): 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: for partition in partitions:
# Skip / and partitions which have no mount points if not partition[ "mountPoint" ]:
if partition[ "mountPoint" ] in ( "/", "" ):
continue 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(): def calamares_main():
rootMountPoint = tempfile.mkdtemp( prefix="calamares-root-" ) 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" ) ) mountPartitions( rootMountPoint, libcalamares.global_storage.value( "partitions" ) )
libcalamares.global_storage.insert( "rootMountPoint", rootMountPoint ) libcalamares.global_storage.insert( "rootMountPoint", rootMountPoint )
return "all done, mounted at {}".format( rootMountPoint ) return "All done, mounted at {}".format( rootMountPoint )

@ -1,6 +1,3 @@
# Module metadata file for dummy process jobmodule
# Syntax is YAML 1.2
---
type: "job" type: "job"
name: "mount" name: "mount"
interface: "python" interface: "python"

Loading…
Cancel
Save