[英]How to get the capacity of a usb pendrive?
I need to get the capacity of a usb pendrive that is unmounted.我需要获得未安装的 usb pendrive 的容量。 I'm using pyudev to detect it, but I don't know how to get the capacity.
我正在使用 pyudev 来检测它,但我不知道如何获得容量。 I read some documentation about pyusb, but I haven't found anything of useful.
我阅读了一些关于 pyusb 的文档,但没有发现任何有用的东西。 Any idea?
任何想法?
The following code taken from here works pretty well:从此处获取的以下代码效果很好:
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
the exact line is the following:确切的行如下:
hdd = {'size': device.attributes.asint('size')}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.