mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
b8fe3e52c9
commit
083f493834
@ -354,6 +354,18 @@ def iterdescendants(parent_devinst):
|
|||||||
for gc in iterdescendants(child):
|
for gc in iterdescendants(child):
|
||||||
yield gc
|
yield gc
|
||||||
|
|
||||||
|
def iterancestors(devinst):
|
||||||
|
NO_MORE = CR_CODES['CR_NO_SUCH_DEVINST']
|
||||||
|
parent = DEVINST(devinst)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
CM_Get_Parent(byref(parent), parent, 0)
|
||||||
|
except WindowsError as err:
|
||||||
|
if err.winerror == NO_MORE:
|
||||||
|
break
|
||||||
|
raise
|
||||||
|
yield parent.value
|
||||||
|
|
||||||
def get_all_removable_drives(allow_fixed=False):
|
def get_all_removable_drives(allow_fixed=False):
|
||||||
mask = GetLogicalDrives()
|
mask = GetLogicalDrives()
|
||||||
ans = {}
|
ans = {}
|
||||||
@ -486,14 +498,9 @@ def get_removable_drives(debug=False): # {{{
|
|||||||
# Get the devpaths for all parents of this device. This is not
|
# Get the devpaths for all parents of this device. This is not
|
||||||
# actually necessary on Vista+, so we simply ignore any windows API
|
# actually necessary on Vista+, so we simply ignore any windows API
|
||||||
# failures.
|
# failures.
|
||||||
parent = DEVINST(devinfo.DevInst)
|
for parent in iterancestors(devinfo.DevInst):
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
CM_Get_Parent(byref(parent), parent, 0)
|
devid, buf = get_device_id(parent, buf=buf)
|
||||||
except WindowsError:
|
|
||||||
break
|
|
||||||
try:
|
|
||||||
devid, buf = get_device_id(parent.value, buf=buf)
|
|
||||||
except WindowsError:
|
except WindowsError:
|
||||||
break
|
break
|
||||||
candidates.append(devid)
|
candidates.append(devid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user