forked from ash-vd/python-networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistener.py
More file actions
33 lines (26 loc) · 895 Bytes
/
listener.py
File metadata and controls
33 lines (26 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Listen to some available signals from NetworkManager
"""
import dbus.mainloop.glib
from gi.repository import GObject
import NetworkManager
import time
def out(msg):
print("%s %s" % (time.strftime('%H:%M:%S'), msg))
def statechange(nm, interface, signal, state):
out("State changed to %s" % NetworkManager.const('STATE', state))
def adddevice(nm, interface, signal, device_path):
try:
out("Device %s added" % device_path.IpInterface)
except NetworkManager.ObjectVanished:
# Sometimes this signal is sent for *removed* devices. Ignore.
pass
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
NetworkManager.NetworkManager.OnStateChanged(statechange)
NetworkManager.NetworkManager.OnDeviceAdded(adddevice)
out("Waiting for signals")
loop = GObject.MainLoop()
loop.run()
if __name__ == '__main__':
main()