Thomas Gläßle avatar Thomas Gläßle committed 44ca021

Add mount/mount_holder functions to make API consistent

Comments (0)

Files changed (2)

     # only mount the desired devices
     elif len(posargs) > 0:
+        mounted = []
         for path in posargs:
-            device = udiskie.device.get_device(mounter.bus, path)
+            device = mounter.mount(path)
             if device:
-                mounter.add_device(device)
+                mounted.append(device)
+        # automatically mount luks holders
+        for device in mounted:
+            mounter.mount_holder(device)
     # run in daemon mode
     elif run_daemon:
     return unmounted
-# lock a slave
+# mount a holder/lock a slave
+def mount_holder(device, filter=None, prompt=None):
+    """
+    Mount or unlock the holder device of this unlocked LUKS device.
+    Will not mount the holder if the device is not unlocked.
+    Return value indicates success
+    """
+    logger = logging.getLogger('udiskie.mount.lock_slave')
+    if not device.is_unlocked:
+        logger.debug('skipping locked or non-luks device %s' % (device,))
+        return False
+    holder_path = device.luks_cleartext_holder
+    holder = udiskie.device.Device(device.bus, holder_path)
+    return add_device(device, filter=filter, prompt=prompt)
 def lock_slave(device):
     Lock the luks slave of this device.
 # mount/unmount by path
+def mount(path, bus=None, filter=None, prompt=None):
+    """
+    Mount or unlock a device.
+    The device must match the criteria for a filesystem mountable or
+    unlockable by udiskie.
+    """
+    logger = logging.getLogger('udiskie.mount.unmount')
+    bus = bus or dbus.SystemBus()
+    device = udiskie.device.get_device(bus, path)
+    if device:
+        logger.debug('found device owning "%s": "%s"' % (path, device))
+        if add_device(device, filter=filter, prompt=prompt):
+            return device
+    return None
 def unmount(path, bus=None):
     Unmount or lock a filesystem
         return unmount_all(self.bus)
     # mount/unmount
+    def mount(self, path, filter=None, prompt=None):
+        return mount(
+                path, bus=self.bus,
+                filter=filter or self.filter,
+                prompt=prompt or self.prompt)
     def unmount(self, path):
         return unmount(path, bus=self.bus)
     # mount_holder/lock_slave
+    def mount_holder(self, device, filter=None, prompt=None):
+        return mount_holder(
+                device,
+                filter=filter or self.filter,
+                prompt=prompt or self.prompt)
     def lock_slave(self, device):
         return lock_slave(device)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.