usbinstall.py: udisks to udisks2 support
This commit is contained in:
parent
bef54500dd
commit
d675d616ea
@ -232,20 +232,32 @@ def get_list():
|
||||
|
||||
# Get list form 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)
|
||||
# If dev.space > 850 MB
|
||||
if(device_props.Get('org.freedesktop.UDisks.Device', 'PartitionSize')) > 891289600:
|
||||
# If dev is removable
|
||||
if(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceIsRemovable')):
|
||||
# Populate the arrays
|
||||
a_path_dev.append(device_props.Get('org.freedesktop.UDisks.Device', 'DeviceFile'))
|
||||
a_dev_model.append(device_props.Get('org.freedesktop.UDisks.Device', 'DriveModel'))
|
||||
ud_manager_obj = bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2')
|
||||
ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.DBus.ObjectManager')
|
||||
for k,v in ud_manager.GetManagedObjects().iteritems():
|
||||
device_block = v.get('org.freedesktop.UDisks2.Block', {})
|
||||
device_partitiontable = v.get('org.freedesktop.UDisks2.PartitionTable', {})
|
||||
device = device_block.get('Device')
|
||||
drive = device_block.get('Drive')
|
||||
if not device or not drive or not device_partitiontable:
|
||||
continue
|
||||
device = bytearray(device).replace(b'\x00', b'').decode('utf-8')
|
||||
device_drive = bus.get_object('org.freedesktop.UDisks2', drive)
|
||||
try:
|
||||
removable = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Removable', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
except:
|
||||
continue
|
||||
size = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Size', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
if removable and size > 891289600 and not device_block.get('ReadOnly') and \
|
||||
not device_block.get('HintSystem') and device_block.get('HintPartitionable'):
|
||||
connectionbus = device_drive.Get('org.freedesktop.UDisks2.Drive', 'ConnectionBus', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
model = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Model', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
vendor = device_drive.Get('org.freedesktop.UDisks2.Drive', 'Vendor', dbus_interface='org.freedesktop.DBus.Properties')
|
||||
if removable:
|
||||
a_path_dev.append(device)
|
||||
a_dev_model.append(vendor + " " + model)
|
||||
# And add element to comboBox
|
||||
window.c_usb.addItem(a_path_dev[i] + " " + a_dev_model[i])
|
||||
window.c_usb.addItem(a_dev_model[i] + " (" + "{0:.2f}".format(size / 1024.0 / 1024.0 / 1024.0) + " GiB)")
|
||||
i += 1
|
||||
|
||||
# First dev is default
|
||||
|
Loading…
Reference in New Issue
Block a user