This commit is contained in:
Kovid Goyal 2012-09-12 14:50:59 +05:30
parent 4b8933f9fb
commit c0aee6772d
2 changed files with 9 additions and 3 deletions

View File

@ -7,7 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import operator, traceback, pprint, sys
import operator, traceback, pprint, sys, time
from threading import RLock
from collections import namedtuple
from functools import partial
@ -16,7 +16,7 @@ from calibre import prints, as_unicode
from calibre.constants import plugins
from calibre.ptempfile import SpooledTemporaryFile
from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
from calibre.devices.mtp.base import MTPDeviceBase, synchronous
from calibre.devices.mtp.base import MTPDeviceBase, synchronous, debug
MTPDevice = namedtuple('MTPDevice', 'busnum devnum vendor_id product_id '
'bcd serial manufacturer product')
@ -193,6 +193,8 @@ class MTP_DEVICE(MTPDeviceBase):
@property
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 = [], [], []
@ -220,6 +222,7 @@ class MTP_DEVICE(MTPDeviceBase):
self.current_friendly_name,
self.format_errorstack(all_errs)))
self._filesystem_cache = FilesystemCache(storage, all_items)
debug('Filesystem metadata loaded in %g seconds'%(time.time()-st))
return self._filesystem_cache
@synchronous

View File

@ -16,7 +16,7 @@ from calibre import as_unicode, prints
from calibre.constants import plugins, __appname__, numeric_version
from calibre.ptempfile import SpooledTemporaryFile
from calibre.devices.errors import OpenFailed, DeviceError, BlacklistedDevice
from calibre.devices.mtp.base import MTPDeviceBase
from calibre.devices.mtp.base import MTPDeviceBase, debug
class ThreadingViolation(Exception):
@ -199,6 +199,8 @@ class MTP_DEVICE(MTPDeviceBase):
@property
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 = []
@ -218,6 +220,7 @@ class MTP_DEVICE(MTPDeviceBase):
all_storage.append(storage)
items.append(id_map.itervalues())
self._filesystem_cache = FilesystemCache(all_storage, chain(*items))
debug('Filesystem metadata loaded in %g seconds'%(time.time()-st))
return self._filesystem_cache
@same_thread