Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Created November 27, 2013 22:40
Show Gist options
  • Save bennuttall/7684385 to your computer and use it in GitHub Desktop.
Save bennuttall/7684385 to your computer and use it in GitHub Desktop.
piosk - some code I found on my laptop written by robie ages ago :/
import dbus
import gobject
from dbus.mainloop.glib import DBusGMainLoop
def device_added_callback(device):
print 'Device %s was added' % (device)
def device_changed_callback(device):
print 'Device %s was changed' % (device)
#must be done before connecting to DBus
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.UDisks",
"/org/freedesktop/UDisks")
iface = dbus.Interface(proxy, "org.freedesktop.UDisks.Device")
devices = iface.get_dbus_method('EnumerateDevices')()
print '%s' % (devices)
#addes two signal listeners
iface.connect_to_signal('DeviceAdded', device_added_callback)
iface.connect_to_signal('DeviceChanged', device_changed_callback)
#start the main loop
mainloop = gobject.MainLoop()
mainloop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment