mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make user_defined_device information work on linux
This commit is contained in:
parent
f74bed6381
commit
0962ebb3ba
@ -162,45 +162,54 @@ 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 dev in devices:
|
||||||
vid = re.search('vid_([0-9a-f]*)&', dev)
|
for i in range(3):
|
||||||
if vid:
|
dev[i] = hex(dev[i])
|
||||||
vid = vid.group(1)
|
d = dev[0] + dev[1] + dev[2]
|
||||||
pid = re.search('pid_([0-9a-f]*)&', dev)
|
device_set.add(d)
|
||||||
if pid:
|
device_details[d] = dev[0:3]
|
||||||
pid = pid.group(1)
|
else:
|
||||||
rev = re.search('rev_([0-9a-f]*)$', dev)
|
for dev in devices:
|
||||||
if rev:
|
vid = re.search('vid_([0-9a-f]*)&', dev)
|
||||||
rev = rev.group(1)
|
if vid:
|
||||||
d = vid+pid+rev
|
vid = vid.group(1)
|
||||||
device_set.add(d)
|
pid = re.search('pid_([0-9a-f]*)&', dev)
|
||||||
device_details[d] = (vid, pid, rev)
|
if pid:
|
||||||
res['device_set'] = device_set
|
pid = pid.group(1)
|
||||||
res['device_details'] = device_details
|
rev = re.search('rev_([0-9a-f]*)$', dev)
|
||||||
drives = win_pnp_drives(debug=False)
|
if rev:
|
||||||
drive_details = {}
|
rev = rev.group(1)
|
||||||
drive_set = set()
|
d = vid+pid+rev
|
||||||
for drive,details in drives.iteritems():
|
device_set.add(d)
|
||||||
order = 'ORD_' + str(drive.order)
|
device_details[d] = (vid, pid, rev)
|
||||||
ven = re.search('VEN_([^&]*)&', details)
|
|
||||||
if ven:
|
drives = win_pnp_drives(debug=False)
|
||||||
ven = ven.group(1)
|
for drive,details in drives.iteritems():
|
||||||
prod = re.search('PROD_([^&]*)&', details)
|
order = 'ORD_' + str(drive.order)
|
||||||
if prod:
|
ven = re.search('VEN_([^&]*)&', details)
|
||||||
prod = prod.group(1)
|
if ven:
|
||||||
d = (order, ven, prod)
|
ven = ven.group(1)
|
||||||
drive_details[drive] = d
|
prod = re.search('PROD_([^&]*)&', details)
|
||||||
drive_set.add(drive)
|
if prod:
|
||||||
res['drive_details'] = drive_details
|
prod = prod.group(1)
|
||||||
res['drive_set'] = drive_set
|
d = (order, ven, prod)
|
||||||
|
drive_details[drive] = d
|
||||||
|
drive_set.add(drive)
|
||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
return res
|
return res
|
||||||
|
@ -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,20 +69,20 @@ 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'
|
||||||
# sort the drives by the order number
|
if iswindows:
|
||||||
for i,d in enumerate(sorted(new_drives,
|
# sort the drives by the order number
|
||||||
key=lambda x: after['drive_details'][x][0])):
|
for i,d in enumerate(sorted(new_drives,
|
||||||
if i == 0:
|
key=lambda x: after['drive_details'][x][0])):
|
||||||
res += _('Windows main memory ID string') + ': ' + \
|
if i == 0:
|
||||||
after['drive_details'][d][1] + '\n'
|
res += _('Windows main memory ID string') + ': ' + \
|
||||||
res += _('Windows main memory ID string') + ': ' + \
|
after['drive_details'][d][1] + '\n'
|
||||||
after['drive_details'][d][2] + '\n'
|
res += _('Windows main memory ID string') + ': ' + \
|
||||||
else:
|
after['drive_details'][d][2] + '\n'
|
||||||
res += _('Windows card A vendor string') + ': ' + \
|
else:
|
||||||
after['drive_details'][d][1] + '\n'
|
res += _('Windows card A vendor string') + ': ' + \
|
||||||
res += _('Windows card A ID string') + ': ' + \
|
after['drive_details'][d][1] + '\n'
|
||||||
after['drive_details'][d][2] + '\n'
|
res += _('Windows card A ID string') + ': ' + \
|
||||||
|
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 '
|
||||||
|
@ -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
|
||||||
|
@ -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 &user defined device (Windows only)</string>
|
<string>Get information to setup the &user defined device</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user