Rewrote from scratch.
[cnetworkmanager.git] / manager.py
blob39417f2d1367f0507855268bcce45cbb34f992c2
1 import dbus
2 import time
3 import object
5 NMI = 'org.freedesktop.NetworkManager'
7 class cNM(object.cObject):
8 # TODO: pull them from introspection.xml
9 NM_STATE = ["UNKNOWN", "ASLEEP", "CONNECTING", "CONNECTED", "DISCONNECTED",]
11 def __init__(self, opath, options):
12 object.cObject.__init__(self, opath)
13 self.nmi = dbus.Interface(self.obj, NMI)
14 self.options = options
16 def prop_iface(self):
17 return NMI
19 def Api(self):
20 return "common"
22 def Dump0(self):
23 "Dumps its own info (not owned objects)."
24 pass
26 def Dump(self):
27 self.Dump0()
28 if self.options.dev:
29 for device in self.Devices():
30 device.Dump()
32 if self.options.actcon:
33 print "Active Connections"
34 aconns = self.ActiveConnections()
35 for aconn in aconns:
36 aconn.Dump()
38 def ListNets(self):
39 print "Wifi Networks:"
40 for dev in self.Devices():
41 dev.ListNets()
43 def err_handler(self, *args):
44 print "ERR:", args
46 def silent_handler(self, *args):
47 pass
48 #print "BOO!:", args
50 def quitter_handler(self, *args):
51 # exit the loop that runs only because of us
52 print "padla"
53 sys.exit(0)
55 def WatchState(self):
56 self.bus.add_signal_receiver(self.state_changed_handler,
57 dbus_interface=NMI,
58 signal_name="StateChanged")
60 def state_changed_handler(self, *args):
61 s = args[0]
62 ss = self.NM_STATE[s]
63 print time.strftime("(%X)"),
64 print "State:", ss