if ismount(mountpoint):
raise RuntimeError("Failed to umount: " + mountpoint)
-def mount(args, source, destination, create_folders=True, umount=False, readonly=True):
+def mount(args, source, destination, create_folders=True, umount=False,
+ readonly=True, mount_type=None, options=None, force=True):
"""
Mount and create necessary directory structure.
:param umount: when destination is already a mount point, umount it first.
+ :param force: attempt mounting even if the mount point already exists.
"""
# Check/umount destination
if ismount(destination):
if umount:
umount_all(args, destination)
else:
- return
+ if not force:
+ return
# Check/create folders
if not os.path.exists(destination):
raise RuntimeError("Mount failed, folder does not exist: " +
destination)
- # Actually mount the folder
- tools.helpers.run.user(args, ["mount", source, destination])
+ extra_args = []
+ opt_args = []
+ if mount_type:
+ extra_args.extend(["-t", mount_type])
if readonly:
- tools.helpers.run.user(args, ["mount", "-o", "remount,ro", source, destination])
+ opt_args.append("ro")
+ if options:
+ opt_args.extend(options)
+ if opt_args:
+ extra_args.extend(["-o", ",".join(opt_args)])
+
+ # Actually mount the folder
+ tools.helpers.run.user(args, ["mount", *extra_args, source, destination])
# Verify, that it has worked
if not ismount(destination):