Example #1
0
 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)
Example #2
0
    def _get_device_info(self, drive):
        id_ = drive.get_identifier('unix-device')
        mount_path = size = remaining = None
        database = devices.DeviceDatabase()
        volumes = drive.get_volumes()
        if volumes:
            volume = volumes[0]
            mount = volume.get_mount()
            if mount:
                mount_path = mount.get_root().get_path()
                if mount_path and os.path.exists(mount_path):
                    if mount_path[-1] != os.path.sep:
                        mount_path = mount_path + os.path.sep # make sure it
                                                              # ends with a /
                    statinfo = os.statvfs(mount_path)
                    size = statinfo.f_frsize * statinfo.f_blocks
                    remaining = statinfo.f_frsize * statinfo.f_bavail
                    database = devices.load_database(mount_path)

        device_info = app.device_manager.get_device(
            drive.get_name(),
            database.get('device_name', None))

        self._unix_device_to_drive[id_] = drive
        return messages.DeviceInfo(id_, device_info, mount_path,
                                   database, size, remaining)
Example #3
0
    def test_load_database_error(self):
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            f.write('NOT JSON DATA')

        ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), {})
        self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #4
0
    def test_load_database_error(self):
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            f.write('NOT JSON DATA')

        ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), {})
        self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #5
0
    def test_load_database(self):
        data = {u'a': 2, u'b': {u'c': [5, 6]}}
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            json.dump(data, f)

        ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), data)
        self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #6
0
    def test_load_database_error(self):
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            f.write('NOT JSON DATA')

        with self.allow_warnings():
            ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), {})
        self.assertNotEqual(ddb.write_manager, None)
Example #7
0
    def test_load_database(self):
        data = {u'a': 2,
                u'b': {u'c': [5, 6]}}
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            json.dump(data, f)

        ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), data)
        self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #8
0
    def test_load_database(self):
        data = {u'a': 2,
                u'b': {u'c': [5, 6]}}
        os.makedirs(os.path.join(self.tempdir, '.miro'))
        with open(os.path.join(self.tempdir, '.miro', 'json'), 'w') as f:
            json.dump(data, f)

        ddb = devices.load_database(self.tempdir)
        self.assertEqual(dict(ddb), data)
        self.assertNotEqual(ddb.write_manager, None)
Example #9
0
    def _get_device_info(self, device):
        mount = device['mount']
	database = devices.load_database(mount)
        device_info = app.device_manager.get_device_by_id(
	    device['vendor_id'], device['product_id'],
            database.get('device_name'))
        if not os.path.exists(mount):
            mount = size = remaining = None
	else:
            available = ctypes.wintypes.LARGE_INTEGER()
            total = ctypes.wintypes.LARGE_INTEGER()
            ctypes.windll.kernel32.GetDiskFreeSpaceExW(unicode(mount),
                                                       ctypes.byref(available),
						       ctypes.byref(total),
                                                       None)
	    remaining = available.value
	    size = total.value
        return messages.DeviceInfo(device['volume'], device_info, mount,
				   database, size, remaining)
Example #10
0
 def test_load_database_missing(self):
     ddb = devices.load_database(self.tempdir)
     self.assertEqual(dict(ddb), {})
     self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #11
0
 def test_load_database_missing(self):
     ddb = devices.load_database(self.tempdir)
     self.assertEqual(dict(ddb), {})
     self.assertEqual(len(ddb.get_callbacks('changed')), 1)
Example #12
0
 def test_load_database_missing(self):
     ddb = devices.load_database(self.tempdir)
     self.assertEqual(dict(ddb), {})
     self.assertNotEqual(ddb.write_manager, None)