mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Remove unused code
This commit is contained in:
parent
b090e5fa6c
commit
382d6de38d
@ -15,7 +15,7 @@ import os, subprocess, time, re, sys, glob
|
|||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from calibre import prints, as_unicode
|
from calibre import prints
|
||||||
from calibre.constants import DEBUG
|
from calibre.constants import DEBUG
|
||||||
from calibre.devices.interface import DevicePlugin
|
from calibre.devices.interface import DevicePlugin
|
||||||
from calibre.devices.errors import DeviceError
|
from calibre.devices.errors import DeviceError
|
||||||
@ -867,7 +867,6 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def eject_windows(self):
|
def eject_windows(self):
|
||||||
from calibre.devices.winusb import eject_drive
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
drives = []
|
drives = []
|
||||||
for x in ('_main_prefix', '_card_a_prefix', '_card_b_prefix'):
|
for x in ('_main_prefix', '_card_a_prefix', '_card_b_prefix'):
|
||||||
@ -876,20 +875,10 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
drives.append(x[0].upper())
|
drives.append(x[0].upper())
|
||||||
|
|
||||||
def do_it(drives):
|
def do_it(drives):
|
||||||
for d in drives:
|
|
||||||
try:
|
|
||||||
eject_drive(d)
|
|
||||||
except Exception as e:
|
|
||||||
try:
|
|
||||||
prints("Eject failed:", as_unicode(e))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def do_it2(drives):
|
|
||||||
import win32process
|
import win32process
|
||||||
subprocess.Popen([eject_exe()] + drives, creationflags=win32process.CREATE_NO_WINDOW).wait()
|
subprocess.Popen([eject_exe()] + drives, creationflags=win32process.CREATE_NO_WINDOW).wait()
|
||||||
|
|
||||||
t = Thread(target=do_it2, args=[drives])
|
t = Thread(target=do_it, args=[drives])
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
self.__save_win_eject_thread = t
|
self.__save_win_eject_thread = t
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
from __future__ import (unicode_literals, division, absolute_import,
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
print_function)
|
print_function)
|
||||||
|
|
||||||
import os, string, _winreg as winreg, re, time, sys
|
import os, string, _winreg as winreg, re, sys
|
||||||
from collections import namedtuple, defaultdict
|
from collections import namedtuple, defaultdict
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from ctypes import (
|
from ctypes import (
|
||||||
@ -792,41 +792,6 @@ def is_usb_device_connected(vendor_id, product_id): # {{{
|
|||||||
return False
|
return False
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def eject_drive(drive_letter): # {{{
|
|
||||||
' Eject the disk that corresponds to the specified drive letter '
|
|
||||||
drive_letter = type('')(drive_letter)[0]
|
|
||||||
volume_access_path = '\\\\.\\' + drive_letter + ':'
|
|
||||||
try:
|
|
||||||
sn = get_storage_number(volume_access_path)[:2]
|
|
||||||
except WindowsError:
|
|
||||||
return True
|
|
||||||
for devinfo, devpath in DeviceSet(guid=GUID_DEVINTERFACE_DISK).interfaces(ignore_errors=True):
|
|
||||||
try:
|
|
||||||
dsn = get_storage_number(devpath)[:2]
|
|
||||||
except WindowsError:
|
|
||||||
continue
|
|
||||||
if dsn == sn:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
parent = DEVINST(0)
|
|
||||||
CM_Get_Parent(byref(parent), devinfo.DevInst, 0)
|
|
||||||
max_tries = 3
|
|
||||||
while max_tries >= 0:
|
|
||||||
max_tries -= 1
|
|
||||||
try:
|
|
||||||
CM_Request_Device_Eject(parent, None, None, 0, 0)
|
|
||||||
except WindowsError:
|
|
||||||
if max_tries < 0:
|
|
||||||
raise
|
|
||||||
time.sleep(0.5)
|
|
||||||
continue
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
def get_usb_info(usbdev, debug=False): # {{{
|
def get_usb_info(usbdev, debug=False): # {{{
|
||||||
'''
|
'''
|
||||||
The USB info (manufacturer/product names and serial number) Requires communication with the hub the device is connected to.
|
The USB info (manufacturer/product names and serial number) Requires communication with the hub the device is connected to.
|
||||||
@ -940,7 +905,7 @@ def is_readonly(drive_letter): # {{{
|
|||||||
return get_volume_information(drive_letter)['FILE_READ_ONLY_VOLUME']
|
return get_volume_information(drive_letter)['FILE_READ_ONLY_VOLUME']
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def develop(do_eject=False): # {{{
|
def develop(): # {{{
|
||||||
from calibre.customize.ui import device_plugins
|
from calibre.customize.ui import device_plugins
|
||||||
usb_devices = scan_usb_devices()
|
usb_devices = scan_usb_devices()
|
||||||
drive_letters = set()
|
drive_letters = set()
|
||||||
@ -966,9 +931,6 @@ def develop(do_eject=False): # {{{
|
|||||||
print('Is device connected:', is_usb_device_connected(*usbdev[:2]))
|
print('Is device connected:', is_usb_device_connected(*usbdev[:2]))
|
||||||
print()
|
print()
|
||||||
print('Device USB data:', get_usb_info(usbdev, debug=True))
|
print('Device USB data:', get_usb_info(usbdev, debug=True))
|
||||||
if do_eject:
|
|
||||||
for drive in drive_letters:
|
|
||||||
eject_drive(drive)
|
|
||||||
|
|
||||||
def drives_for(vendor_id, product_id=None):
|
def drives_for(vendor_id, product_id=None):
|
||||||
usb_devices = scan_usb_devices()
|
usb_devices = scan_usb_devices()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user