[Mailman-Developers] Mailman + DB: Snag

Chris Ryan chris@greatbridge.com
Tue, 20 Mar 2001 11:32:01 -0500


This is a multi-part message in MIME format.
--------------57A9CB433680A9C255ED813D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

	I worked through the problem (as described below) that I was
encountering for the datasource driver stuff. I've attached a patch for
your approval to be applied to the current cvs tree that changes the
setattr and getattr functions in admin.py to call mlist.getProperty()
mlist.setProperty() instead. Also includes the changes to add
getProperty and setProperty to MailList.py. These changes will make it
possible continue with the datasource driver development without needing
and overhaul on the whole admin.py.

	At this time getProperty and setProperty just call getattr and setattr
but when I start integrating the datasource driver code i will change it
to an eval/exec of some kind to call the driver interface function
instead.

Chris Ryan
chris@greatbridge.com



Chris Ryan wrote:
> 
>         As a test I implemented a basic interface driver with mailman that
> loaded the config.db and implemented the internalName() and realName()
> methods. Everything worked fine which was good except one thing.
> 
>         The way the admin.py update the attributes does not work with the
> interface driver. I'm trying to find a reasonable solution that would
> allow the current code to work as it stands without having to overhaul
> the entire web interface update code.
> 
>         One possible solution that I can think of is to replace the getattr()
> setattr() methods that are currently used with a similar function that
> would instead use a switched case on the variable to know which
> attribute the get/set.
> 
> for example:
> 
>     Current method:
>         property = 'real_name'
>         value = getattr(mlist,property,'some default')
> 
>         setattr(mlist,property, value)
> 
>     New method (concept):
> 
>         property = 'real_name'
>         value = mlist.getProperty(property,'some default')
> 
>         mlist.setProperty(property, value)
> 
>         def MailList.getProperty(self, property, default=None)
>             if property == 'real_name':
>                 return self.list_data.realName()
>             elif property == '...':
>             elif property == '...':
>             else:
>                 if default:
>                     return default
>                 else:
>                     raise AttributeError
> 
>         I'll have to look through the python documentation to see if there is a
> way to dynamically call a method as that would further simplify the
> above. Does this sound reasonable? Or is there a better way to deal with
> this problem?
> 
> Chris Ryan
> chris@greatbridge.org
> 
> _______________________________________________
> Mailman-Developers mailing list
> Mailman-Developers@python.org
> http://mail.python.org/mailman/listinfo/mailman-developers
--------------57A9CB433680A9C255ED813D
Content-Type: text/plain; charset=us-ascii;
 name="getsetmod.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="getsetmod.diff"

Index: Mailman/MailList.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/MailList.py,v
retrieving revision 2.9
diff -r2.9 MailList.py
1404a1405,1412
> 
>     def setProperty(self,property, value):
>         setattr(self,property,value)
> 
>     def getProperty(self,property,default=None):
>         if default is None:
>             return getattr(self,property)
>         return getattr(self,property,default)
Index: Mailman/Cgi/admin.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Cgi/admin.py,v
retrieving revision 2.10
diff -r2.10 admin.py
516c516
<             checked = getattr(mlist, varname)
---
>             checked = mlist.getProperty(varname)
522c522
<         return TextBox(varname, getattr(mlist, varname), params)
---
>         return TextBox(varname, mlist.getProperty(varname), params)
528c528
<         val = getattr(mlist, varname)
---
>         val = mlist.getProperty(varname)
537c537
<         res = NL.join(getattr(mlist, varname))
---
>         res = NL.join(mlist.getProperty(varname))
545c545
<         val = getattr(mlist, varname)
---
>         val = mlist.getProperty(varname)
787c787
<         return getattr(mlist, prop)
---
>         return mlist.getProperty(prop)
811c811
<             return getattr(mlist, prop)
---
>             return mlist.getProperty(prop)
892c892
<             elif getattr(mlist, property) <> value:
---
>             elif mlist.getProperty(property) <> value:
908c908
<                 setattr(mlist, property, value)
---
>                 mlist.setProperty(property, value)

--------------57A9CB433680A9C255ED813D--