Wednesday, February 08, 2006

Repository reordering

People requested that I move some code from the objectrealms.net svn and darcs repos into the collective. I've been hoping that people would try darcs to get at some of the code in that repo (which we think is quite good) but people haven't and it doesn't look like this changes. So I am going to fold.

Bricolite:: https://svn.plone.org/svn/collective/bricolite/

Skeletor:: https://svn.plone.org/svn/collective/skeletor

Expect Chimera soon, the newer versions of that have Archetypes widgets included that can do things like render textual images in the font and style of your choice directly from data kept in Archetypes objects.

The mdns patch for Zope

People asked for it. This is about the simplest version of the thing I could come up with but you will need the Avahi and DBUS Python bindings up and running. After that this patch should apply to the Zope 2.8/2.9 releases pretty easily.

Then you just restart Zope and you should see these services on your network.


diff -ur Zope-2.8.5-final/lib/python/ZServer/FTPServer.py Zope-2.8.5-mdns/lib/python/ZServer/FTPServer.py
--- Zope-2.8.5-final/lib/python/ZServer/FTPServer.py 2005-12-18 23:25:56.000000000 -0800
+++ Zope-2.8.5-mdns/lib/python/ZServer/FTPServer.py 2006-02-08 12:46:15.000000000 -0800
@@ -80,6 +80,7 @@
import marshal
import stat
import time
+from utils import mdns_announce


class zope_ftp_channel(ftp_channel):
@@ -640,6 +641,10 @@
self.hostname,
self.port
))
+ mdns_announce(None,
+ self.port,
+ service="_ftp._tcp")
+

def clean_shutdown_control(self,phase,time_in_this_phase):
if phase==2:
diff -ur Zope-2.8.5-final/lib/python/ZServer/HTTPServer.py Zope-2.8.5-mdns/lib/python/ZServer/HTTPServer.py
--- Zope-2.8.5-final/lib/python/ZServer/HTTPServer.py 2005-12-18 23:25:56.000000000 -0800
+++ Zope-2.8.5-mdns/lib/python/ZServer/HTTPServer.py 2006-02-08 12:47:46.000000000 -0800
@@ -58,6 +58,7 @@
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
import DebugLogger
from medusa import logger
+from utils import mdns_announce

register_subsystem('ZServer HTTPServer')

@@ -384,6 +385,7 @@
server_protocol = 'HTTP'
channel_class = zhttp_channel
shutup=0
+ service = "_http._tcp"

def __init__ (self, ip, port, resolver=None, logger_object=None):
self.shutup=1
@@ -397,6 +399,9 @@
self.server_port
))

+ self.mdns = mdns_announce(None, port, service = self.service, info=self.SERVER_IDENT)
+
+
def clean_shutdown_control(self,phase,time_in_this_phase):
if phase==2:
self.log_info('closing %s to new connections' % self.server_protocol)
@@ -422,3 +427,4 @@

class zwebdav_server(zhttp_server):
server_protocol = 'WebDAV'
+ service = "_webdav._tcp"
diff -ur Zope-2.8.5-final/lib/python/ZServer/utils.py Zope-2.8.5-mdns/lib/python/ZServer/utils.py
--- Zope-2.8.5-final/lib/python/ZServer/utils.py 2005-12-18 23:25:56.000000000 -0800
+++ Zope-2.8.5-mdns/lib/python/ZServer/utils.py 2006-02-08 12:48:02.000000000 -0800
@@ -56,3 +56,39 @@
from medusa import logger
# override the service name in logger.syslog_logger
logger.syslog_logger.svc_name='ZServer'
+try:
+ import avahi, dbus, dbus.glib
+ hostname = None
+ def mdns_announce(name, port, service="_http._tcp",
+ **kwargs):
+ global hostname
+ 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)
+
+
+ if name is None:
+ if hostname is None:
+ hostname = "%s:%s" % (server.GetHostName(), port)
+ name = hostname
+
+ info = ["%s=%s" % (k,v) for k,v in kwargs.items()]
+ g.AddService(avahi.IF_UNSPEC,
+ avahi.PROTO_UNSPEC, 0,
+ name,
+ service,
+ "", "", # domain, host (let the system figure it out)
+ dbus.UInt16(port),
+ info,
+ )
+ g.Commit()
+ return g
+
+except ImportError:
+ def mdns_announce(server, name, port): pass
+

Thursday, February 02, 2006

Bonjour Zope


So I thought how nice would it be for Zope to announce itself using Zero Configuration technology on the network. On Linux we have Avahi and DBUS which make it easy to do such publications. Happily they both have simple Python bindings as well. With a small patch I was able to get my Zope servers to announce themselves on startup for HTTP, FTP and WebDav. They will automatically show up in tools like Nautilus (on GNOME) or Finder (on Mac OS X).

This has got to be nice in situations like Sprints where bunches of developers are passing links to DHCP generated address around adhoc networks. Heck, its nice just when I can't remember which port I left something on.

Followers