Skip to content

Instantly share code, notes, and snippets.

@alyssonbruno
Last active October 6, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alyssonbruno/3022589 to your computer and use it in GitHub Desktop.
Save alyssonbruno/3022589 to your computer and use it in GitHub Desktop.
Alterando o label de um disco, com dbus
import dbus
def changelabel(device, newlabel):
"""Change label of device.
>>> changelabel('/dev/sdc1','Boot')
True
>>> changelabel('/dev/sxpto','Data')
False
"""
res = False
try:
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.UDisks','/org/freedesktop/UDisks')
iface = dbus.Interface(proxy, 'org.freedesktop.UDisks')
for dev in iface.EnumerateDevices():
dev_obj = bus.get_object('org.freedesktop.UDisks', dev)
dev_prop = dbus.Interface(dev_obj, 'org.freedesktop.DBus.Properties')
if dev_prop.Get('','DeviceFile')==device:
idev = dbus.Interface(dev_obj, 'org.freedesktop.DBus.UDisks.Device')
idev.get_dbus_method('FilesystemSetLabel', dbus_interface='org.freedesktop.UDisks.Device')(newlabel)
res = True
finally:
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment