It is because I am doing a complete rewrite, based on an easy-to-use library that hides some rough edges in dbus-python. If you ever thought NM needed some programmatic prodding but were put off by the tedious details, the library might be just the thing for you. For me, it is also an opportunity to learn more Python.
Compare how you get the interface names.
Before:
After:#! /usr/bin/python
import dbus
bus = dbus.SystemBus()
NM = 'org.freedesktop.NetworkManager'
nm = bus.get_object(NM, '/org/freedesktop/NetworkManager')
for dev_opath in nm.GetDevices(dbus_interface = NM):
dev = bus.get_object(NM, dev_opath)
print dev.Get(NM + '.Device', 'Interface',
dbus_interface='org.freedesktop.DBus.Properties')
It is in the librarize branch of the git repo. Beware, the code is still messy. Getting it:#! /usr/bin/python
from networkmanager.networkmanager import NetworkManager
nm = NetworkManager()
for d in nm.GetDevices():
print d["Interface"]
git clone git://repo.or.cz/cnetworkmanager.git cnetworkmanager.librarize
cd cnetworkmanager.librarize
git checkout -b librarize origin/librarize
./cnetworkmanager -h
5 comments:
Why not make the python interface to networkmanager a separate project? Or perhaps a part of upstream?
Yes, that's the plan.
v0.20 is now merged in the master branch. It is still messy, but does nearly everything that v0.8.4 did.
Awesome!
I've spent a long time trying to connect to a NetworkManager event with python without success. Tried with your bindings, and it works!
#! /usr/bin/python
import gobject
import dbus, dbus.service
from dbus.mainloop.glib import DBusGMainLoop
dbus_loop=DBusGMainLoop()
dbus.set_default_main_loop(dbus_loop)
from networkmanager.networkmanager import NetworkManager
def nState(state):
print 'New State'
print state
nm = NetworkManager()
nm.connect_to_signal('StateChanged',nState)
loop = gobject.MainLoop()
loop.run()
Yes, that's the plan.
Post a Comment