[Namazu-users-en] Program to integrate namazu with mailman

Lindsay Haisley fmouse-namazu at fmp.com
Mon Oct 16 04:46:45 JST 2006


I'm attaching a Python program, nmzproc, which greatly simplifies the 
integration of namazu with the mailman list server program.

The program requires that the account using it (on my system, nmz) be in the 
'mailman' group.  Invoke it with a list name as its only argument.

The program uses local copies of the namazu templates to generate the per-list 
copies of these files.  These are expected to be in ~/templates/.  NMZ.head, 
NMZ.foot and .mknmzrc ('~/templates/mknmzrc' without the dot) are processed for 
subsitution placeholders which are replaced with information from the target 
list configuration.  Currently the following list-specific variables are 
recognized.

List Variable			Template Placeholder
----------------------------------------------------
owner (email address)		${owner}
List name (from cmd line)	${list}
real_name			${real_name}
host_name			${listinfo} (full URL for list information)
description			&{description}

Additionally, nmzproc copies NMZ.body, NMZ.result.normal, NMZ.result.short and 
NMZ.tips as-is from the local template directory to the namazu list specific 
directory without any placeholder processing.  I've edited NMZ.body for my own 
use, "de-geeking" it substantially.  Many of my customers who manage mailing 
lists have no idea what Emcacs and FreeBSD are!  Technical names are replaced 
with fruit and vegetable names.  Everyone understands food!

I'm probably going to expand this utility somewhat, possibly include support 
for a loccal .nmzprocrc file, support for more list variables (easily done by 
adding them to tdict dictionary defined on line 34).  Future work on this will 
be posted at http://www.fmp.com/namazu (not yet available).  I'll add a short 
README, put version info in it, and set up a Changes file.  I'll notify this 
list and the developers list.

Contributions are welcome.

-- 
Lindsay Haisley       | "Fighting against human |     PGP public key
FMP Computer Services |    creativity is like   |      available at
512-259-1190          |    trying to eradicate  | <http://pubkeys.fmp.com>
http://www.fmp.com    |        dandelions"      |
                      |      (Pamela Jones)     |
-------------- next part --------------
#!/usr/bin/python
import sys
import os
import string

def document():
	print """Usage: nmzproc listname
"""

sys.path.extend(['/usr/local/mailman'])
try:
	app = sys.argv[1]
except IndexError:
	document()
	sys.exit(1)

from Mailman import MailList
try:
	mlist = MailList.MailList(app, lock=False)

except MailList.Errors.MMUnknownListError:
	print "%s: Unknown list: %s" % ((lambda st: string.split(st, "/")[-1])(sys.argv[0]), app)
	sys.exit(1)

owner = mlist.owner[0]
descrip = mlist.description
host_name = mlist.host_name
real_name = mlist.real_name

listinfo = "http://" + host_name + "/mailman/listinfo/" + app

home = os.getenv("HOME")

tdict = {"owner" : owner, 
	"list" : app,
	"real_name" : real_name,
	"listinfo" : listinfo,
	"description" : descrip}

head_th = open(home + "/templates/NMZ.head", "r")
head_ts = head_th.read()
head_tt = string.Template(head_ts)

foot_th = open(home + "/templates/NMZ.foot", "r")
foot_ts = foot_th.read()
foot_tt = string.Template(foot_ts)

nmrc_th = open(home + "/templates/mknmzrc", "r")
nmrc_ts = nmrc_th.read()
nmrc_tt = string.Template(nmrc_ts)

# We have all the basic info now.  Let's create the directory and get
# on with it.

try:
	os.mkdir(home + "/" + app)
except OSError:
	pass

head_wh = open(home + "/" + app + "/NMZ.head", "w")
head_wh.write(head_tt.safe_substitute(tdict))
head_wh.close()
print "Writing NMZ.head ..."

foot_wh = open(home + "/" + app + "/NMZ.foot", "w")
foot_wh.write(foot_tt.safe_substitute(tdict))
foot_wh.close()
print "Writing NMZ.foot ..."

nmrc_wh = open(home + "/" + app + "/.mknmzrc", "w")
nmrc_wh.write(nmrc_tt.safe_substitute(tdict))
nmrc_wh.close()
print "Writing .mknmzrc ..."

body_th = open(home + "/templates/NMZ.body", "r")
body_wh = open(home + "/" + app + "/NMZ.body", "w")
body_wh.write(body_th.read())
body_wh.close()
print "Writing NMZ.body ..."

resshort_th = open(home + "/templates/NMZ.result.short", "r")
resshort_wh = open(home + "/" + app + "/NMZ.result.short", "w")
resshort_wh.write(resshort_th.read())
resshort_wh.close()
print "Writing NMZ.result.short"

resnorm_th = open(home + "/templates/NMZ.result.normal", "r")
resnorm_wh = open(home + "/" + app + "/NMZ.result.normal", "w")
resnorm_wh.write(resnorm_th.read())
resnorm_wh.close()
print "writing NMZ.result.normal ..."

tips_th = open(home + "/templates/NMZ.tips", "r")
tips_wh = open(home + "/" + app + "/NMZ.tips", "w")
tips_wh.write(tips_th.read())
tips_wh.close()
print "Writing NMZ.tips ..."




More information about the Namazu-users-en mailing list