本文介绍了python udisks-枚举设备信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用udisks二进制文件显然可以获得与附加磁盘有关的很多信息:

It's apparently possible to get a lot of info relating to attached disks using the udisks binary:

udisks --show-info /dev/sda1

udisks显然只是枚举udev可用的数据.

udisks is apparently just enumerating the data which is available udev.

是否可以使用python获取此信息?例如说说我是否只想检索设备序列号,安装点和大小.

Is it possible to get this information using python? say for example if i just wanted to retrieve the device serial, mount point and size.

推荐答案

您可以直接在python中通过dbus使用Udisk.

You can use Udisks via dbus directly in python.

import dbus

bus = dbus.SystemBus()
ud_manager_obj = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks')

for dev in ud_manager.EnumerateDevices():
    device_obj = bus.get_object("org.freedesktop.UDisks", dev)
    device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE)
    print device_props.Get('org.freedesktop.UDisks.Device', "DriveVendor")
    print device_props.Get('org.freedesktop.UDisks.Device', "DeviceMountPaths")
    print device_props.Get('org.freedesktop.UDisks.Device', "DriveSerial")
    print device_props.Get('org.freedesktop.UDisks.Device', "PartitionSize")

此处提供了完整的属性列表 http://hal.freedesktop.org/docs/udisks/Device.html

The full list of properties available is here http://hal.freedesktop.org/docs/udisks/Device.html

这篇关于python udisks-枚举设备信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 13:03