[avahi] python and zeroconf

Lennart Poettering lennart at poettering.de
Wed Aug 3 06:18:07 EST 2005


On Tue, 02.08.05 21:43, Sebastien Estienne (sebastien.estienne at gmail.com) wrote:

> > I am still ondering if there is a realy need for a "binding". The
> > python wrapper of DBUS is pretty comfortable to use, so what could an
> > explicit binding offer in addition?
> > 
> > See hal as an example: they include some python tools with their
> > distribution (including hal-device-manager) but didn't bother to write
> > "python-hal".

> did you had a quick look at the api of the first link i posted?

Yes.

> In fact i wanted to do something like this to hide the dbus things.
> That's true that the dbus Api may be enough, but i wanted to play a
> bit more with python and maybe something usefull will come from it,
> (maybe not) :)

I don't see how that API is superior to using our DBUS directly:

Their example:

<snip>
import Zeroconf
import socket

server = Zeroconf.Zeroconf()

# Get local IP address
local_ip = socket.gethostbyname(socket.gethostname())
local_ip = socket.inet_aton(local_ip)

svc1 = Zeroconf.ServiceInfo('_durus._tcp.local.',
                              'Database 1._durus._tcp.local.',
                              address = local_ip,
                              port = 2972,
                              weight = 0, priority=0,
                              properties = {'description':
                                            'Departmental server'}
                             )
server.registerService(svc1)
</snip>

Our equivalent:

<snip>
import avahi, dbus, dbus.glib

bus = dbus.SystemBus()
server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)

g = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, name, stype, domain, host, dbus.UInt16(port), txt)
g.Commit()
</snip>

This example is really bad, since it doesn't care about conflict
detection and things, but the other ain't any better.

For a better example see:

http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/avahi-utils/avahi-publish-service?root=flexmdns&view=auto

The pyzeroconf API looks a bit "javaish" to me. It uses listener
objects which isn't very pythonesque, I believe.

But anyway, surprise me with your work, and I will certainly change my
mind on this topic.

Lennart

-- 
Lennart Poettering; lennart [at] poettering [dot] de
ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/


More information about the avahi mailing list