importloggingimportosDBUS_PROPS_INTERFACE='org.freedesktop.DBus.Properties'UDISKS_INTERFACE='org.freedesktop.UDisks'UDISKS_DEVICE_INTERFACE='org.freedesktop.UDisks.Device'UDISKS_OBJECT='org.freedesktop.UDisks'UDISKS_OBJECT_PATH='/org/freedesktop/UDisks'classDevice:def__init__(self,bus,device_path):self.log=logging.getLogger('udiskie.device.Device')self.bus=busself.device_path=device_pathself.device=self.bus.get_object(UDISKS_OBJECT,device_path)def__str__(self):returnself.device_pathdef_get_property(self,property):returnself.device.Get(UDISKS_DEVICE_INTERFACE,property,dbus_interface=DBUS_PROPS_INTERFACE)defpartition_slave(self):returnself._get_property('PartitionSlave')defis_partition_table(self):returnself._get_property('DeviceIsPartitionTable')defis_systeminternal(self):returnself._get_property('DeviceIsSystemInternal')defis_handleable(self):"""Should this device be handled by udiskie? Currently this just means that the device is removable and holds a filesystem."""ifself.is_filesystem()andnotself.is_systeminternal():returnTrueelse:returnFalsedefis_mounted(self):returnself._get_property('DeviceIsMounted')defmount_paths(self):raw_paths=self._get_property('DeviceMountPaths')return[os.path.normpath(path)forpathinraw_paths]defdevice_file(self):returnos.path.normpath(self._get_property('DeviceFile'))defis_filesystem(self):returnself._get_property('IdUsage')=='filesystem'defid_type(self):returnself._get_property('IdType')defmount(self,filesystem,options):self.device.FilesystemMount(filesystem,options,dbus_interface=UDISKS_DEVICE_INTERFACE)defunmount(self):self.device.FilesystemUnmount([],dbus_interface=UDISKS_DEVICE_INTERFACE)defget_all(bus):udisks=bus.get_object(UDISKS_OBJECT,UDISKS_OBJECT_PATH)forpathinudisks.EnumerateDevices(dbus_interface=UDISKS_INTERFACE):yieldDevice(bus,path)