Created
March 31, 2020 07:23
-
-
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
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 | |
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