[Mailman-Developers] More extend.py questions

Barry A. Warsaw barry@python.org
Mon Nov 4 21:50:10 2002

>>>>> "MW" == Martin Whinnery <martin.whinnery@sbc.ac.uk> writes:

    MW> Please indulge a python virgin. Barry has advised someone to
    MW> 'overload the Load & Save function' in extend.py . Would
    MW> someone help me with a little sample? It doesn't need to do
    MW> anything useful, just replace the original function.

Understand that this stuff is a kludge that should make /some/ radical
customization of Mailman easier.  The specific use case I had in mind
was the ability to create different MemberAdaptor implementations,
which I think is pretty close to what you're trying to do.

Note that you may or may not need to overload MailList.Load() and
MailList.Save() unless you also want to customize how list attributes
are stored.  If all you care about is getting member information out
of LDAP, you might only need to set the MailList object's
_memberadaptor attribute to something other than an
OldStyleMemberships instance.

    --------- My efforts so far -------------
    # /usr/local/mailman/lists/ldaplist/extend.py

    def extend(mlist):
	    mlist.OldSave = mlist.Save
	    def MySave(self):
		    print "WOOKIE" # So I can see it in withlist
	    mlist.Save = MySave

    -------- snip snip ----------------------

I think this is pretty close to what I had in mind, although I'm not
sure why you want to call the original Save function in MySave(), and
why you wouldn't just call mlist.OldSave() if you really wanted to do

    But when I try m.Save(m) from within "withlist ldaplist", I get a
    'NotLocked' error:

    NotLockedError: <LockFile
    137391332: /usr/local/mailman/locks/ldaplist.lock [unlocked: 18000sec]
    pid=9172>: None

Did you use the -l option to withlist?  Or did you explicit call
m.Lock()?  If not, getting this exception probably has little to do
with extend.py (the list has to be locked in order to Save it).

But as I said, I'm not sure you'll need to override Load() and
Save() -- unless you're going to allow the writeable methods in the
MemberAdaptor interface to be called through Mailman.

You'll definitely want to write an implementation of MemberAdaptor
that gets its data through LDAP, and then in your extend.py file, do
something like

-------------------- snip snip --------------------
# extend.py

def extend(mlist):
    # You might want to key off of something other than the list's
    # internal name.
    listid = mlist.internal_name()
    # Get all member info from LDAP
    mlist._memberadaptor = LDAPMemberAdaptor(listid)
-------------------- snip snip --------------------