我需要获得一个未安装的usb penddrive的容量。我正在使用pyudev来检测它,但我不知道如何获得容量。我读了一些关于pyusb的文档,但没有发现任何有用的东西。知道吗?
从这里获得的以下代码运行得很好:
def query_hdd_model() -> t.Dict[str, dict]:
"""Get information about all hard drives."""
if not HDD:
return {}
context = pyudev.Context()
hdds = {}
for device in context.list_devices(subsystem='block', DEVTYPE='disk'):
if any(_ in device.device_path for _ in IGNORED_DEVICE_PATHS):
continue
hdd = {'size': device.attributes.asint('size')}
for device_ in itertools.chain([device], device.ancestors):
try:
hdd['model'] = device_.attributes.asstring('model')
break
except KeyError:
hdd['model'] = ''
hdds[device.device_node] = hdd
确切的线路如下:
hdd = {'size': device.attributes.asint('size')}