[avahi] python and zeroconf

Sebastien Estienne sebastien.estienne at gmail.com
Wed Aug 3 07:28:25 EST 2005


2005/8/2, Lennart Poettering <lennart at poettering.de>:
> 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
> 
Sure the differences aren't big, it was only a matter of hiding dbus,
and it's specificity that (IMO) make the code harder to read and
require some dbus knowledge (things like dbus.UInt16(port)). And i
think that you example is a good one to show just this. But i agree
that the difference is slim.

> 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.
If i could surprise you with my 2 days of python knowledge, it would
surprise me :D
Sure i'm far from being the right guy to write a good pythonesque Api.
I think we should ask some python gurus, but it's optional for a 0.1 release.

> 
> Lennart
> 
> --
> Lennart Poettering; lennart [at] poettering [dot] de
> ICQ# 11060553; GPG 0x1A015CC4; http://0pointer.de/lennart/
> _______________________________________________
> avahi mailing list
> avahi at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/avahi
> 


-- 
Sebastien Estienne


More information about the avahi mailing list