Jul 21, 2009

HackWeek: NetworkManager Python library

It is Hack Week again, a time when we venture into unexplored territories. So why am I returning to cnetworkmanager?

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.
#! /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',
#! /usr/bin/python
from networkmanager.networkmanager import NetworkManager
nm = NetworkManager()
for d in nm.GetDevices():
print d["Interface"]
It is in the librarize branch of the git repo. Beware, the code is still messy. Getting it:
git clone git://repo.or.cz/cnetworkmanager.git cnetworkmanager.librarize
cd cnetworkmanager.librarize
git checkout -b librarize origin/librarize
./cnetworkmanager -h

Jul 8, 2009

D-Bus and Ruby

There isn't a canonical D-Bus library for Ruby. I found four projects, two of which are interesting.

First, the two losers:
* dbus-ruby: It wraps the C bindings. It is dead (last release in January 2005).
* pr-dbus: No releases, last SVN commit in April 2007, entirely in Ruby.

Now for the contenders. Both are packaged as RPMs in the OBS YaST:Web project.
The developers know about each other but in 2007 they did not want to merge the projects. The developers are not active but patches do appear.

* ruby-dbus
  • LGPL
  • no test suite (but I've started one together with bug fixes: Github clone)
  • can export services
  • cumbersome API (explicit introspection calls needed, explicit types for variants needed, return value must be an array)
BTW Klaus has two posts about writing a client and a server with ruby-dbus.

* rbus
  • GPL
  • test suite (RSpec, needs a patch)
  • cannot export services
WebYaST is using ruby-dbus so far, but I am looking at rbus too because of the tests and and the nicer API.