#!/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 ..."