mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
pep8
This commit is contained in:
parent
db195e6b75
commit
f10a409a38
@ -52,7 +52,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
def is_device_mtp(self, d, debug=None):
|
def is_device_mtp(self, d, debug=None):
|
||||||
''' Returns True iff the _is_device_mtp check returns True and libmtp
|
''' Returns True iff the _is_device_mtp check returns True and libmtp
|
||||||
is able to probe the device successfully. '''
|
is able to probe the device successfully. '''
|
||||||
if self._is_device_mtp is None: return False
|
if self._is_device_mtp is None:
|
||||||
|
return False
|
||||||
return (self._is_device_mtp(d, debug=debug) and
|
return (self._is_device_mtp(d, debug=debug) and
|
||||||
self.libmtp.is_mtp_device(d.busnum, d.devnum))
|
self.libmtp.is_mtp_device(d.busnum, d.devnum))
|
||||||
|
|
||||||
@ -61,7 +62,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
|
|
||||||
@synchronous
|
@synchronous
|
||||||
def detect_managed_devices(self, devices_on_system, force_refresh=False):
|
def detect_managed_devices(self, devices_on_system, force_refresh=False):
|
||||||
if self.libmtp is None: return None
|
if self.libmtp is None:
|
||||||
|
return None
|
||||||
# First remove blacklisted devices.
|
# First remove blacklisted devices.
|
||||||
devs = set()
|
devs = set()
|
||||||
for d in devices_on_system:
|
for d in devices_on_system:
|
||||||
@ -109,13 +111,14 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
p(err)
|
p(err)
|
||||||
return False
|
return False
|
||||||
devs = [d for d in devices_on_system if
|
devs = [d for d in devices_on_system if
|
||||||
( (d.vendor_id, d.product_id) in self.known_devices or
|
((d.vendor_id, d.product_id) in self.known_devices or
|
||||||
self.is_device_mtp(d, debug=p)) and d.vendor_id != APPLE]
|
self.is_device_mtp(d, debug=p)) and d.vendor_id != APPLE]
|
||||||
if not devs:
|
if not devs:
|
||||||
p('No MTP devices connected to system')
|
p('No MTP devices connected to system')
|
||||||
return False
|
return False
|
||||||
p('MTP devices connected:')
|
p('MTP devices connected:')
|
||||||
for d in devs: p(d)
|
for d in devs:
|
||||||
|
p(d)
|
||||||
|
|
||||||
for d in devs:
|
for d in devs:
|
||||||
p('\nTrying to open:', d)
|
p('\nTrying to open:', d)
|
||||||
@ -144,7 +147,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
|
|
||||||
@synchronous
|
@synchronous
|
||||||
def eject(self):
|
def eject(self):
|
||||||
if self.currently_connected_dev is None: return
|
if self.currently_connected_dev is None:
|
||||||
|
return
|
||||||
self.ejected_devices.add(self.currently_connected_dev)
|
self.ejected_devices.add(self.currently_connected_dev)
|
||||||
self.post_yank_cleanup()
|
self.post_yank_cleanup()
|
||||||
|
|
||||||
@ -244,7 +248,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
storage, all_items, all_errs = [], [], []
|
storage, all_items, all_errs = [], [], []
|
||||||
for sid, capacity in zip([self._main_id, self._carda_id,
|
for sid, capacity in zip([self._main_id, self._carda_id,
|
||||||
self._cardb_id], self.total_space()):
|
self._cardb_id], self.total_space()):
|
||||||
if sid is None: continue
|
if sid is None:
|
||||||
|
continue
|
||||||
name = _('Unknown')
|
name = _('Unknown')
|
||||||
for x in self.dev.storage_info:
|
for x in self.dev.storage_info:
|
||||||
if x['id'] == sid:
|
if x['id'] == sid:
|
||||||
@ -384,7 +389,8 @@ def develop():
|
|||||||
dev.startup()
|
dev.startup()
|
||||||
try:
|
try:
|
||||||
cd = dev.detect_managed_devices(scanner.devices)
|
cd = dev.detect_managed_devices(scanner.devices)
|
||||||
if cd is None: raise RuntimeError('No MTP device found')
|
if cd is None:
|
||||||
|
raise RuntimeError('No MTP device found')
|
||||||
dev.open(cd, 'develop')
|
dev.open(cd, 'develop')
|
||||||
pprint.pprint(dev.dev.storage_info)
|
pprint.pprint(dev.dev.storage_info)
|
||||||
dev.filesystem_cache
|
dev.filesystem_cache
|
||||||
|
@ -80,7 +80,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
|
|
||||||
@same_thread
|
@same_thread
|
||||||
def detect_managed_devices(self, devices_on_system, force_refresh=False):
|
def detect_managed_devices(self, devices_on_system, force_refresh=False):
|
||||||
if self.wpd is None: return None
|
if self.wpd is None:
|
||||||
|
return None
|
||||||
if self.eject_dev_on_next_scan:
|
if self.eject_dev_on_next_scan:
|
||||||
self.eject_dev_on_next_scan = False
|
self.eject_dev_on_next_scan = False
|
||||||
if self.currently_connected_pnp_id is not None:
|
if self.currently_connected_pnp_id is not None:
|
||||||
@ -166,7 +167,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
p(traceback.format_exc())
|
p(traceback.format_exc())
|
||||||
continue
|
continue
|
||||||
protocol = data.get('protocol', '').lower()
|
protocol = data.get('protocol', '').lower()
|
||||||
if not protocol.startswith('mtp:'): continue
|
if not protocol.startswith('mtp:'):
|
||||||
|
continue
|
||||||
p('MTP device:', pnp_id)
|
p('MTP device:', pnp_id)
|
||||||
p(pprint.pformat(data))
|
p(pprint.pformat(data))
|
||||||
if not self.is_suitable_wpd_device(data):
|
if not self.is_suitable_wpd_device(data):
|
||||||
@ -195,10 +197,12 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
def is_suitable_wpd_device(self, devdata):
|
def is_suitable_wpd_device(self, devdata):
|
||||||
# Check that protocol is MTP
|
# Check that protocol is MTP
|
||||||
protocol = devdata.get('protocol', '').lower()
|
protocol = devdata.get('protocol', '').lower()
|
||||||
if not protocol.startswith('mtp:'): return False
|
if not protocol.startswith('mtp:'):
|
||||||
|
return False
|
||||||
|
|
||||||
# Check that the device has some read-write storage
|
# Check that the device has some read-write storage
|
||||||
if not devdata.get('has_storage', False): return False
|
if not devdata.get('has_storage', False):
|
||||||
|
return False
|
||||||
has_rw_storage = False
|
has_rw_storage = False
|
||||||
for s in devdata.get('storage', []):
|
for s in devdata.get('storage', []):
|
||||||
if s.get('filesystem', None) == 'DCF':
|
if s.get('filesystem', None) == 'DCF':
|
||||||
@ -206,11 +210,12 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
# See https://bugs.launchpad.net/calibre/+bug/1054562
|
# See https://bugs.launchpad.net/calibre/+bug/1054562
|
||||||
continue
|
continue
|
||||||
if s.get('type', 'unknown_unknown').split('_')[-1] == 'rom':
|
if s.get('type', 'unknown_unknown').split('_')[-1] == 'rom':
|
||||||
continue # Read only storage
|
continue # Read only storage
|
||||||
if s.get('rw', False):
|
if s.get('rw', False):
|
||||||
has_rw_storage = True
|
has_rw_storage = True
|
||||||
break
|
break
|
||||||
if not has_rw_storage: return False
|
if not has_rw_storage:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -234,7 +239,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
items = []
|
items = []
|
||||||
for storage_id, capacity in zip([self._main_id, self._carda_id,
|
for storage_id, capacity in zip([self._main_id, self._carda_id,
|
||||||
self._cardb_id], ts):
|
self._cardb_id], ts):
|
||||||
if storage_id is None: continue
|
if storage_id is None:
|
||||||
|
continue
|
||||||
name = _('Unknown')
|
name = _('Unknown')
|
||||||
for s in self.dev.data['storage']:
|
for s in self.dev.data['storage']:
|
||||||
if s['id'] == storage_id:
|
if s['id'] == storage_id:
|
||||||
@ -245,7 +251,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
self._currently_getting_sid = unicode(storage_id)
|
self._currently_getting_sid = unicode(storage_id)
|
||||||
id_map = self.dev.get_filesystem(storage_id,
|
id_map = self.dev.get_filesystem(storage_id,
|
||||||
self._filesystem_callback)
|
self._filesystem_callback)
|
||||||
for x in id_map.itervalues(): x['storage_id'] = storage_id
|
for x in id_map.itervalues():
|
||||||
|
x['storage_id'] = storage_id
|
||||||
all_storage.append(storage)
|
all_storage.append(storage)
|
||||||
items.append(id_map.itervalues())
|
items.append(id_map.itervalues())
|
||||||
self._filesystem_cache = FilesystemCache(all_storage, chain(*items))
|
self._filesystem_cache = FilesystemCache(all_storage, chain(*items))
|
||||||
@ -255,7 +262,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
|
|
||||||
@same_thread
|
@same_thread
|
||||||
def do_eject(self):
|
def do_eject(self):
|
||||||
if self.currently_connected_pnp_id is None: return
|
if self.currently_connected_pnp_id is None:
|
||||||
|
return
|
||||||
self.ejected_devices.add(self.currently_connected_pnp_id)
|
self.ejected_devices.add(self.currently_connected_pnp_id)
|
||||||
self.currently_connected_pnp_id = self.current_friendly_name = None
|
self.currently_connected_pnp_id = self.current_friendly_name = None
|
||||||
self._main_id = self._carda_id = self._cardb_id = None
|
self._main_id = self._carda_id = self._cardb_id = None
|
||||||
@ -273,7 +281,8 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
return self.currently_connected_pnp_id is not None
|
return self.currently_connected_pnp_id is not None
|
||||||
|
|
||||||
def eject(self):
|
def eject(self):
|
||||||
if self.currently_connected_pnp_id is None: return
|
if self.currently_connected_pnp_id is None:
|
||||||
|
return
|
||||||
self.eject_dev_on_next_scan = True
|
self.eject_dev_on_next_scan = True
|
||||||
self.current_serial_num = None
|
self.current_serial_num = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user