genPersist (version 1.4.1, 18 August 2004)
index
m:\projects\genesis-python\1.4.1\genpersist.py

Modules for joining Genesis 2000 scripting and the Python scripting language.
 
This module provides a persistency framework for the Genesis-Python interface.
Arbitrary Python objects may be stored directly into the Genesis job structure...placed
into a storage bucket, which ends up being the misc directory...
 
This arbitrary Python object can then be read back into memory during a later
session, thus providing a simple multi-session persistency model.  One of the storage
formats is XML, used if the bucket is instantiated as an instance of XmlBucket.
By default, the XmlBucket is used if gnosis.xml.pickle is installed.  You may choose
to modify that behaviour, however.
 
This model provides NO concurrency control, as it should generally not be needed.
 
Usage:
>>> job = genClasses.Job('test_job')
>>> job.open()
>>> myDict = {'thiskey': 22.354, 'thatkey': 16.402, 'otherkey': (1,0,0,3)}
>>> job.bucket.put(myDict, 'map_dict')
 
 
... days later ...
 
 
>>> job = genClasses.Job('test_job')
>>> job.open()
>>> myDict = job.bucket.get('map_dict')
>>> print myDict
{'thiskey': 22.354, 'thatkey': 16.402, 'otherkey': (1,0,0,3)}
 
NOTES: 
- Some special Python objects are not supported by this persistence model...specifically,
  genClasses.Job objects cannot be saved due to their special handling of __getattr__ calls.
 
- In order to use the XmlBucket class, the gnosis.xml modules must be installed.  You can get
  them from http://www.gnosis.cx/download/Gnosis_Utils-current.tar.gz and installed using distutils.
  (
    e.g. untar the stuff, cd to the directory and run 
    python setup.py build
    python setup.py install
  )

 
Modules
       
os
cPickle
string
gnosis.xml.pickle

 
Classes
       
Bucket
XmlBucket

 
class Bucket
    The basic unit of persistency.  This class represents a storage bucket,
which may have many objects stored within it.  Those objects may be of various
types.
 
  Methods defined here:
__init__(self, job)
Needs the genClasses.Job object instance passed in as a parameter
exists(self, name)
This (public) method checks to see if the name already exists
Returns 0 if not, 1 if it exists...
get(self, name, raw=0)
This method gets an object out of the bucket 
If the name does not exist, this method returns 1
Optional raw parameter will return the data raw (e.g. pickled)
put(self, obj, name, overwrite=0)
This method provides a way to place the object into the bucket
usage: job.bucket.put(obj, 'cur_state')
If the name already exists, and overwrite is set to 0 (default) then
this method will return 1

 
class XmlBucket(Bucket)
    Subclass of Bucket, implementing xml.pickle instead of standard cPickle 
This Class can only store Instance objects (e.g. classes).  
If you want to store regular objects like dictionaries, just wrap them up as
in an instance of the genClasses.Empty class :
        obj = genClasses.Empty()
        obj.dict = myPreviousDict
        job.bucket.put(obj, 'mydict')
 
  Methods defined here:
__init__(self, job)

Methods inherited from Bucket:
exists(self, name)
This (public) method checks to see if the name already exists
Returns 0 if not, 1 if it exists...
get(self, name, raw=0)
This method gets an object out of the bucket 
If the name does not exist, this method returns 1
Optional raw parameter will return the data raw (e.g. pickled)
put(self, obj, name, overwrite=0)
This method provides a way to place the object into the bucket
usage: job.bucket.put(obj, 'cur_state')
If the name already exists, and overwrite is set to 0 (default) then
this method will return 1

 
Data
        ENGINE = 'XML'
__author__ = 'Mike J. Hopkins'
__credits__ = ' Guido ... and David Mertz for gnosis.xml.pickle'
__date__ = '18 August 2004'
__version__ = '$Revision: 1.4.1 $'

 
Author
        Mike J. Hopkins

 
Credits
         Guido ... and David Mertz for gnosis.xml.pickle