Byron Clark avatar Byron Clark committed 6a7a8dc

Small umount refactor.

Comments (0)

Files changed (2)

-- case in log messages
 - distutils
 - Scan disks on startup

udiskie/umount.py

 
 import udiskie.device
 
+def unmount_device(device):
+    """Unmount a Device.
+
+    Checks to make sure the device is unmountable and then unmounts."""
+
+    logger = logging.getLogger('udiskie.umount.unmount_device')
+    if device.is_handleable() and device.is_mounted():
+        logger.debug('unmounting device %s' % (device,))
+        device.unmount()
+        logger.info('unmounted device %s' % (device,))
+    else:
+        logger.info('skipping unhandled device %s' % (device,))
+
 def unmount(path):
     """Unmount a filesystem
 
     bus = dbus.SystemBus()
     for device in udiskie.device.get_all(bus):
         if path in device.mount_paths() or path == device.device_file():
-            logger.debug('Found device owning "%s": "%s"' % (path, device))
-            if device.is_handleable() and device.is_mounted():
-                logger.debug('Unmounting %s (device: %s)' % (path, device))
-                device.unmount()
-                logger.info('Unmounted %s' % (path,))
-            else:
-                logger.info('Skipping unhandled device %s' % (device,))
+            logger.debug('found device owning "%s": "%s"' % (path, device))
+            unmount_device(device)
 
 def unmount_all():
     """Unmount all filesystems handleable by udiskie."""
     logger = logging.getLogger('udiskie.umount.unmount_all')
     bus = dbus.SystemBus()
     for device in udiskie.device.get_all(bus):
-        if device.is_handleable() and device.is_mounted():
-            logger.debug('Unmounting device: %s' % (device,))
-            device.unmount()
-            logger.info('Unmounted device: %s' % (device,))
-        else:
-            logger.debug('Skipping unhandled device %s' % (device,))
+        unmount_device(device)
 
 def cli(args):
     logger = logging.getLogger('udiskie.umount.cli')
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 ProjectModifiedEvent.java.
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.