Make user_defined_device information work on linux

This commit is contained in:
Charles Haley 2011-05-02 14:58:26 +01:00
parent f74bed6381
commit 0962ebb3ba
4 changed files with 66 additions and 56 deletions

View File

@ -162,14 +162,28 @@ def device_info(ioreg_to_tmp=False, buf=None):
import re import re
res = {} res = {}
if not iswindows: device_details = {}
return None device_set = set()
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: try:
s = DeviceScanner() s = DeviceScanner()
s.scan() s.scan()
devices = (s.devices) devices = (s.devices)
device_details = {} if not iswindows:
device_set = set() devices = [list(x) for x in devices]
for dev in devices:
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: for dev in devices:
vid = re.search('vid_([0-9a-f]*)&', dev) vid = re.search('vid_([0-9a-f]*)&', dev)
if vid: if vid:
@ -183,11 +197,8 @@ def device_info(ioreg_to_tmp=False, buf=None):
d = vid+pid+rev d = vid+pid+rev
device_set.add(d) device_set.add(d)
device_details[d] = (vid, pid, rev) device_details[d] = (vid, pid, rev)
res['device_set'] = device_set
res['device_details'] = device_details
drives = win_pnp_drives(debug=False) drives = win_pnp_drives(debug=False)
drive_details = {}
drive_set = set()
for drive,details in drives.iteritems(): for drive,details in drives.iteritems():
order = 'ORD_' + str(drive.order) order = 'ORD_' + str(drive.order)
ven = re.search('VEN_([^&]*)&', details) ven = re.search('VEN_([^&]*)&', details)
@ -199,8 +210,6 @@ def device_info(ioreg_to_tmp=False, buf=None):
d = (order, ven, prod) d = (order, ven, prod)
drive_details[drive] = d drive_details[drive] = d
drive_set.add(drive) drive_set.add(drive)
res['drive_details'] = drive_details
res['drive_set'] = drive_set
finally: finally:
pass pass
return res return res

View File

@ -10,6 +10,8 @@ __docformat__ = 'restructuredtext en'
from PyQt4.Qt import QDialog, QVBoxLayout, QPlainTextEdit, QTimer, \ from PyQt4.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)
@ -26,10 +28,10 @@ class UserDefinedDevice(QDialog):
self.setLayout(self._layout) self.setLayout(self._layout)
self.log = QPlainTextEdit(self) self.log = QPlainTextEdit(self)
self._layout.addWidget(self.log) self._layout.addWidget(self.log)
self.log.setPlainText(_('Getting debug information')+'...') self.log.setPlainText(_('Getting device information')+'...')
self.copy = QPushButton(_('Copy to &clipboard')) self.copy = QPushButton(_('Copy to &clipboard'))
self.copy.setDefault(True) self.copy.setDefault(True)
self.setWindowTitle(_('Debug device detection')) self.setWindowTitle(_('User-defined device information'))
self.setWindowIcon(QIcon(I('debug.png'))) self.setWindowIcon(QIcon(I('debug.png')))
self.copy.clicked.connect(self.copy_to_clipboard) self.copy.clicked.connect(self.copy_to_clipboard)
self.ok = QPushButton('&OK') self.ok = QPushButton('&OK')
@ -59,7 +61,7 @@ class UserDefinedDevice(QDialog):
new_drives = after['drive_set'] - before['drive_set'] 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 len(new_drives) and len(new_devices) == 1: if (not iswindows or len(new_drives)) and len(new_devices) == 1:
for d in new_devices: for d in new_devices:
res = _('USB Vendor ID (in hex)') + ': 0x' + \ res = _('USB Vendor ID (in hex)') + ': 0x' + \
after['device_details'][d][0] + '\n' after['device_details'][d][0] + '\n'
@ -67,6 +69,7 @@ class UserDefinedDevice(QDialog):
after['device_details'][d][1] + '\n' after['device_details'][d][1] + '\n'
res += _('USB Revision ID (in hex)') + ': 0x' + \ res += _('USB Revision ID (in hex)') + ': 0x' + \
after['device_details'][d][2] + '\n' after['device_details'][d][2] + '\n'
if iswindows:
# sort the drives by the order number # sort the drives by the order number
for i,d in enumerate(sorted(new_drives, for i,d in enumerate(sorted(new_drives,
key=lambda x: after['drive_details'][x][0])): key=lambda x: after['drive_details'][x][0])):
@ -80,7 +83,6 @@ class UserDefinedDevice(QDialog):
after['drive_details'][d][1] + '\n' after['drive_details'][d][1] + '\n'
res += _('Windows card A ID string') + ': ' + \ res += _('Windows card A ID string') + ': ' + \
after['drive_details'][d][2] + '\n' after['drive_details'][d][2] + '\n'
trailer = _('Enter the above values into the USER_DEVICE by ' trailer = _('Enter the above values into the USER_DEVICE by '
'customizing the device plugin. Be sure to also ' 'customizing the device plugin. Be sure to also '
'enter the folders where you want the books to ' 'enter the folders where you want the books to '

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, Setting from calibre.gui2.preferences import ConfigWidgetBase, test_widget, Setting
from calibre.gui2.preferences.misc_ui import Ui_Form from calibre.gui2.preferences.misc_ui import Ui_Form
from calibre.gui2 import error_dialog, config, open_local_file, info_dialog from calibre.gui2 import error_dialog, config, open_local_file, info_dialog
from calibre.constants import isosx, iswindows from calibre.constants import isosx
class WorkersSetting(Setting): class WorkersSetting(Setting):
@ -33,7 +33,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.user_defined_device_button.clicked.connect(self.user_defined_device) self.user_defined_device_button.clicked.connect(self.user_defined_device)
self.button_osx_symlinks.clicked.connect(self.create_symlinks) self.button_osx_symlinks.clicked.connect(self.create_symlinks)
self.button_osx_symlinks.setVisible(isosx) self.button_osx_symlinks.setVisible(isosx)
self.user_defined_device_button.setVisible(iswindows)
def debug_device_detection(self, *args): def debug_device_detection(self, *args):
from calibre.gui2.preferences.device_debug import DebugDevice from calibre.gui2.preferences.device_debug import DebugDevice

View File

@ -61,7 +61,7 @@
<item row="4" column="0" colspan="2"> <item row="4" column="0" colspan="2">
<widget class="QPushButton" name="user_defined_device_button"> <widget class="QPushButton" name="user_defined_device_button">
<property name="text"> <property name="text">
<string>Get information to setup the &amp;user defined device (Windows only)</string> <string>Get information to setup the &amp;user defined device</string>
</property> </property>
</widget> </widget>
</item> </item>