Пример #1
0
 def filesystem_cache(self):
     if self._filesystem_cache is None:
         debug('Loading filesystem metadata...')
         st = time.time()
         from calibre.devices.mtp.filesystem_cache import FilesystemCache
         ts = self.total_space()
         all_storage = []
         items = []
         for storage_id, capacity in zip([self._main_id, self._carda_id,
             self._cardb_id], ts):
             if storage_id is None:
                 continue
             name = _('Unknown')
             for s in self.dev.data['storage']:
                 if s['id'] == storage_id:
                     name = s['name']
                     break
             storage = {'id':storage_id, 'size':capacity, 'name':name,
                     'is_folder':True, 'can_delete':False, 'is_system':True}
             self._currently_getting_sid = unicode(storage_id)
             id_map = self.dev.get_filesystem(storage_id, partial(
                     self._filesystem_callback, {}))
             for x in id_map.itervalues():
                 x['storage_id'] = storage_id
             all_storage.append(storage)
             items.append(id_map.itervalues())
         self._filesystem_cache = FilesystemCache(all_storage, chain(*items))
         debug('Filesystem metadata loaded in %g seconds (%d objects)'%(
             time.time()-st, len(self._filesystem_cache)))
     return self._filesystem_cache
Пример #2
0
 def filesystem_cache(self):
     if self._filesystem_cache is None:
         st = time.time()
         debug('Loading filesystem metadata...')
         from calibre.devices.mtp.filesystem_cache import FilesystemCache
         with self.lock:
             storage, all_items, all_errs = [], [], []
             for sid, capacity in zip(
                 [self._main_id, self._carda_id, self._cardb_id],
                     self.total_space()):
                 if sid is None:
                     continue
                 name = _('Unknown')
                 for x in self.dev.storage_info:
                     if x['id'] == sid:
                         name = x['name']
                         break
                 storage.append({
                     'id': sid,
                     'size': capacity,
                     'is_folder': True,
                     'name': name,
                     'can_delete': False,
                     'is_system': True
                 })
                 self._currently_getting_sid = str(sid)
                 items, errs = self.dev.get_filesystem(
                     sid, partial(self._filesystem_callback, {}))
                 all_items.extend(items), all_errs.extend(errs)
             if not all_items and all_errs:
                 raise DeviceError(
                     'Failed to read filesystem from %s with errors: %s' %
                     (self.current_friendly_name,
                      self.format_errorstack(all_errs)))
             if all_errs:
                 prints('There were some errors while getting the '
                        ' filesystem from %s: %s' %
                        (self.current_friendly_name,
                         self.format_errorstack(all_errs)))
             self._filesystem_cache = FilesystemCache(storage, all_items)
         debug('Filesystem metadata loaded in %g seconds (%d objects)' %
               (time.time() - st, len(self._filesystem_cache)))
     return self._filesystem_cache