Created
November 27, 2013 22:40
-
-
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 :/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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