importwarningswarnings.filterwarnings("ignore",".*could not open display.*",Warning)warnings.filterwarnings("ignore",".*g_object_unref.*",Warning)importloggingimportoptparseimportosimportdbusimportgioimportpynotifyimportudiskie.devicedefunmount_device(device):"""Unmount a Device. Checks to make sure the device is unmountable and then unmounts."""logger=logging.getLogger('udiskie.umount.unmount_device')ifdevice.is_handleable()anddevice.is_mounted():try:device.unmount()logger.info('unmounted device %s'%(device,))exceptdbus.exceptions.DBusException,dbus_err:logger.error('failed to unmount device %s: %s'%(device,dbus_err))returntry:pynotify.Notification('Device unmounted','%s unmounted'%(device.device_file(),),'drive-removable-media').show()exceptgio.Error:passelse:logger.debug('skipping unhandled device %s'%(device,))defunmount(path):"""Unmount a filesystem The filesystem must match the criteria for a filesystem mountable by udiskie. path is either the physical device node (e.g. /dev/sdb1) or the mount point (e.g. /media/Foo)."""logger=logging.getLogger('udiskie.umount.unmount')bus=dbus.SystemBus()fordeviceinudiskie.device.get_all(bus):ifpathindevice.mount_paths()orpath==device.device_file():logger.debug('found device owning "%s": "%s"'%(path,device))unmount_device(device)defunmount_all():"""Unmount all filesystems handleable by udiskie."""bus=dbus.SystemBus()fordeviceinudiskie.device.get_all(bus):unmount_device(device)defcli(args):logger=logging.getLogger('udiskie.umount.cli')parser=optparse.OptionParser()parser.add_option('-a','--all',action='store_true',dest='all',default=False,help='all devices')parser.add_option('-v','--verbose',action='store_true',dest='verbose',default=False,help='verbose output')(options,args)=parser.parse_args(args)log_level=logging.INFOifoptions.verbose:log_level=logging.DEBUGlogging.basicConfig(level=log_level,format='%(message)s')pynotify.init('udiskie.umount')ifoptions.all:unmount_all()else:iflen(args)==0:logger.warn('No devices provided for unmount')return1forpathinargs:unmount(os.path.normpath(path))