Forgot to update the user defined device driver to work with the new windows device detection

This commit is contained in:
Kovid Goyal 2016-02-02 00:39:33 +05:30
parent dfd3be5b56
commit 1c580d1eba
3 changed files with 39 additions and 104 deletions

View File

@ -194,59 +194,17 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None,
pass pass
def device_info(ioreg_to_tmp=False, buf=None): def device_info(ioreg_to_tmp=False, buf=None):
from calibre.devices.scanner import DeviceScanner, win_pnp_drives from calibre.devices.scanner import DeviceScanner
from calibre.constants import iswindows
import re
res = {} res = {}
device_details = {} res['device_set'] = device_set = set()
device_set = set() res['device_details'] = device_details = {}
drive_details = {}
drive_set = set()
res['device_set'] = device_set
res['device_details'] = device_details
res['drive_details'] = drive_details
res['drive_set'] = drive_set
try: s = DeviceScanner()
s = DeviceScanner() s.scan()
s.scan() devices = s.devices
devices = (s.devices) devices = [tuple(x) for x in devices]
if not iswindows: for dev in devices:
devices = [list(x) for x in devices] device_set.add(dev)
for dev in devices: device_details[dev] = dev[0:3]
for i in range(3):
dev[i] = hex(dev[i])
d = dev[0] + dev[1] + dev[2]
device_set.add(d)
device_details[d] = dev[0:3]
else:
for dev in devices:
vid = re.search('vid_([0-9a-f]*)&', dev)
if vid:
vid = vid.group(1)
pid = re.search('pid_([0-9a-f]*)&', dev)
if pid:
pid = pid.group(1)
rev = re.search('rev_([0-9a-f]*)$', dev)
if rev:
rev = rev.group(1)
d = vid+pid+rev
device_set.add(d)
device_details[d] = (vid, pid, rev)
drives = win_pnp_drives(debug=False)
for drive,details in drives.iteritems():
order = 'ORD_' + str(drive.order)
ven = re.search('VEN_([^&]*)&', details)
if ven:
ven = ven.group(1)
prod = re.search('PROD_([^&]*)&', details)
if prod:
prod = prod.group(1)
d = (order, ven, prod)
drive_details[drive] = d
drive_set.add(drive)
finally:
pass
return res return res

View File

@ -34,41 +34,33 @@ class USER_DEFINED(USBMS):
SUPPORTS_SUB_DIRS = True SUPPORTS_SUB_DIRS = True
EXTRA_CUSTOMIZATION_MESSAGE = [ EXTRA_CUSTOMIZATION_MESSAGE = [
_('USB Vendor ID (in hex)') + ':::<p>' + _('USB Vendor ID (in hex)') + ':::<p>' + _(
_('Get this ID using Preferences -> Misc -> Get information to ' 'Get this ID using Preferences -> Misc -> Get information to '
'set up the user-defined device') + '</p>', 'set up the user-defined device') + '</p>',
_('USB Product ID (in hex)')+ ':::<p>' + _('USB Product ID (in hex)')+ ':::<p>' + _(
_('Get this ID using Preferences -> Misc -> Get information to ' 'Get this ID using Preferences -> Misc -> Get information to '
'set up the user-defined device') + '</p>', 'set up the user-defined device') + '</p>',
_('USB Revision ID (in hex)')+ ':::<p>' + _('USB Revision ID (in hex)')+ ':::<p>' + _(
_('Get this ID using Preferences -> Misc -> Get information to ' 'Get this ID using Preferences -> Misc -> Get information to '
'set up the user-defined device') + '</p>', 'set up the user-defined device') + '</p>',
'', '',
_('Windows main memory vendor string') + ':::<p>' + _('Unused (leave blank)') + ':::<p>' + _(
_('This field is used only on windows. ' 'This field is no longer used, leave it blank.') + '</p>',
'Get this ID using Preferences -> Misc -> Get information to ' _('Unused (leave blank)') + ':::<p>' + _(
'set up the user-defined device') + '</p>', 'This field is no longer used, leave it blank.') + '</p>',
_('Windows main memory ID string') + ':::<p>' + _('Unused (leave blank)') + ':::<p>' + _(
_('This field is used only on windows. ' 'This field is no longer used, leave it blank.') + '</p>',
'Get this ID using Preferences -> Misc -> Get information to ' _('Unused (leave blank)') + ':::<p>' + _(
'set up the user-defined device') + '</p>', 'This field is no longer used, leave it blank.') + '</p>',
_('Windows card A vendor string') + ':::<p>' + _('Main memory folder') + ':::<p>' + _(
_('This field is used only on windows. ' 'Enter the folder where the books are to be stored. This folder '
'Get this ID using Preferences -> Misc -> Get information to ' 'is prepended to any send_to_device template') + '</p>',
'set up the user-defined device') + '</p>', _('Card A folder') + ':::<p>' + _(
_('Windows card A ID string') + ':::<p>' + 'Enter the folder where the books are to be stored. This folder '
_('This field is used only on windows. ' 'is prepended to any send_to_device template') + '</p>',
'Get this ID using Preferences -> Misc -> Get information to ' _('Swap main and card A') + ':::<p>' + _(
'set up the user-defined device') + '</p>', 'Check this box if the device\'s main memory is being seen as '
_('Main memory folder') + ':::<p>' + 'card a and the card is being seen as main memory') + '</p>',
_('Enter the folder where the books are to be stored. This folder '
'is prepended to any send_to_device template') + '</p>',
_('Card A folder') + ':::<p>' +
_('Enter the folder where the books are to be stored. This folder '
'is prepended to any send_to_device template') + '</p>',
_('Swap main and card A') + ':::<p>' +
_('Check this box if the device\'s main memory is being seen as '
'card a and the card is being seen as main memory') + '</p>',
] ]
EXTRA_CUSTOMIZATION_DEFAULT = [ EXTRA_CUSTOMIZATION_DEFAULT = [
'0xffff', '0xffff',

View File

@ -10,8 +10,6 @@ __docformat__ = 'restructuredtext en'
from PyQt5.Qt import QDialog, QVBoxLayout, QPlainTextEdit, QTimer, \ from PyQt5.Qt import QDialog, QVBoxLayout, QPlainTextEdit, QTimer, \
QDialogButtonBox, QPushButton, QApplication, QIcon, QMessageBox QDialogButtonBox, QPushButton, QApplication, QIcon, QMessageBox
from calibre.constants import iswindows
def step_dialog(parent, title, msg, det_msg=''): def step_dialog(parent, title, msg, det_msg=''):
d = QMessageBox(parent) d = QMessageBox(parent)
d.setWindowTitle(title) d.setWindowTitle(title)
@ -60,11 +58,12 @@ class UserDefinedDevice(QDialog):
self.close() self.close()
return return
after = device_info() after = device_info()
new_drives = after['drive_set'] - before['drive_set']
new_devices = after['device_set'] - before['device_set'] new_devices = after['device_set'] - before['device_set']
res = '' res = ''
if (not iswindows or len(new_drives)) and len(new_devices) == 1: if len(new_devices) == 1:
def fmtid(x): def fmtid(x):
if isinstance(x, (int, long)):
x = hex(x)
if not x.startswith('0x'): if not x.startswith('0x'):
x = '0x' + x x = '0x' + x
return x return x
@ -76,20 +75,6 @@ class UserDefinedDevice(QDialog):
fmtid(after['device_details'][d][1]) + '\n' fmtid(after['device_details'][d][1]) + '\n'
res += _('USB Revision ID (in hex)') + ': ' + \ res += _('USB Revision ID (in hex)') + ': ' + \
fmtid(after['device_details'][d][2]) + '\n' fmtid(after['device_details'][d][2]) + '\n'
if iswindows:
# sort the drives by the order number
for i,d in enumerate(sorted(new_drives,
key=lambda x: after['drive_details'][x][0])):
if i == 0:
res += _('Windows main memory vendor string') + ': ' + \
after['drive_details'][d][1] + '\n'
res += _('Windows main memory ID string') + ': ' + \
after['drive_details'][d][2] + '\n'
else:
res += _('Windows card A vendor string') + ': ' + \
after['drive_details'][d][1] + '\n'
res += _('Windows card A ID string') + ': ' + \
after['drive_details'][d][2] + '\n'
trailer = _( trailer = _(
'Copy these values to the clipboard, paste them into an ' 'Copy these values to the clipboard, paste them into an '
'editor, then enter them into the USER_DEVICE by ' 'editor, then enter them into the USER_DEVICE by '