[FRPythoneers] Need some conceptual help with persistence.

Brian Jarrett bjarrett at garcoschools.org
Wed Jun 9 10:31:18 MDT 2004


I'm working on a project that will hopefully enable us to handle data mangling from one system to another.  I'm trying to make it flexible enough to reuse whenever we have to take data from one database or file and put it in another database or file.

I've been using ZODB and came up with this:

class fielddef(Persistent):
    def __init__(self, descrip, length, type, ljustify, zeropad, map = {} ):
        self.descrip = descrip
        self.length = length
        self.type = type
        self.ljustify = ljustify
        self.zeropad = zeropad
        self.map = map
    def setformatstring(self):
        formatstring = '%'
        if self.ljustify:
            formatstring = formatstring + '-'
        if self.zeropad:
            formatstring = formatstring + '0'
        if self.length:
            formatstring = formatstring + '%d' %self.length
        if self.type == 'Alpha':
            formatstring = formatstring + 's'
            formatstring = formatstring + 'd'
        self.formatstring = formatstring
    def setlongname(self, value):
        self.descrip = value
    def setleftjustify(self, value):
        self.ljustify = value
    def setzerofill(self, value):
        self.zeropad = value
    def setlength(self, value):
        self.length = value
    def settype(self, value):
        self.type = value
    def run(self, value):
        if self.map:
            value = self.map[value]
        return self.formatstring %value

So now I have objects stored in the zodb and I can get to them, call run(value) and it will return a text value with the appropriate string formatting (using the ones I need to create my reports.)  The problem is that I can't just peek into the object database to see what objects I have and how they are set.  I was thinking it might be better if I had all the settings for each object in a mysql table and then just create all the objects when I run the program by querying a mysql table.  That way, at least, I could use any number of tools to view and manage the mysql table.  Eventually I want a non-programmer to be able to configure new "conversion objects" and set them appropriately.  (I did some prototyping of a GUI interface using wxPython that could view and edit the object's attributes.  The problem is that anytime I added a new class of conversion I'd have to modify the GUI as well.)

I also want to have other objects that, for instance, slice up text and determine a date from it and store it as a date in another database.  Obviously this would require an entirely different class, with different attributes and methods.

I was going then to create a report object that would pair a piece of data with the appropriate conversion object and then save the result in the appropriate place (I have specific need for storing things in a database and also in a flat file.)

I guess basically what I need is a way for me to create plugins or extensions that will handle data the way it needs to be handled.  Once I add the plugin to the program it needs to be accessible to a non-programmer that can then set the conversion with whatever parameters are needed and give it data to work on.

Make sense?

They way I have it now works, but is not very extensible.  Any comments/suggestions/pointers would be MUCH appreciated.


Any ideas on how I could better handle conversion classes so non-programmers could create, view, and modify  an object would be appreciated.

More information about the FRPythoneers mailing list