Skip to content

Instantly share code, notes, and snippets.

@realbardia
Created March 31, 2020 07:23
Show Gist options
  • Save realbardia/ec6669e89001cbe008d423544e98b334 to your computer and use it in GitHub Desktop.
Save realbardia/ec6669e89001cbe008d423544e98b334 to your computer and use it in GitHub Desktop.
Python code to connect to dbus and notify when a storage device connected
import dbus
from gi.repository import GLib
from dbus.mainloop.glib import DBusGMainLoop
def signal_handler(*args, **kwargs):
for i, arg in enumerate(args):
print("arg:%d %s" % (i, str(arg)))
print('---end----')
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
#register your signal callback
bus.add_signal_receiver(signal_handler,
bus_name='org.freedesktop.UDisks2',
interface_keyword='org.freedesktop.DBus.ObjectManager',
member_keyword='interfacesAdded',
path_keyword='/org/freedesktop/UDisks2',
message_keyword='msg')
loop = GLib.MainLoop()
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment