def _disk_mounted(self, volume): volume_info = diskutil('info', volume) if not volume_info: logging.debug('unknown device connected @ %r' % volume) return if volume_info.BusProtocol != 'USB': return # don't care about non-USB devices volume = volume_info.MountPoint disk_info = diskutil('info', volume_info.ParentWholeDisk) if not disk_info: logging.debug('unknown device connected @ %r' % volume) return device_name = disk_info.MediaName[:-6] # strip off ' Media' database = devices.load_database(volume) try: device_info = app.device_manager.get_device( device_name, database.get('device_name')) except KeyError: logging.debug('unknown device connected: %r' % device_name) return logging.debug('seen device: %r' % device_name) self._info_for_volume[volume] = device_info info = messages.DeviceInfo(volume, device_info, volume + '/', database, volume_info.TotalSize, volume_info.FreeSpace) devices.device_connected(info)
def _device_connected(self, device): try: info = self._get_device_info(device) except KeyError: logging.debug('unknown device connected: %r' % (device,)) return logging.debug('seen device: %r' % (device,)) if not info.mount: # we don't get notified :( so poll instead timer.add(0.5, self._check_device_mount, device) devices.device_connected(info)
def _drive_connected(self, volume_monitor, drive): if drive is None: # can happen when a CD is inserted return try: info = self._get_device_info(drive) except KeyError: logging.debug('unknown device connected: %r' % drive.get_name()) return logging.debug('seen device: %r', drive.get_name()) if info.id in self._disconnecting: # Gio sends a disconnect/connect pair when the device is mounted so # we wait a little and check for spurious ones timeout_id = self._disconnecting.pop(info.id) timer.cancel(timeout_id) return devices.device_connected(info)