[Zope] Using __setstate__?

Matt matt@inuan.com
Thu, 31 Jul 2003 11:32:32 +1200


you could set a version as a Class attribute (not a data(instance) 
attribute), and get __setstate__ to check this against a version stored 
as a data(instance attribute).  If they are different, then apply the 
upgrades to the instance and update the instance version to the current 
class version.  If they are already the same, then you simply pass 
through :-)



Terry Hancock wrote:

>Hi all,
>I need to check for upgrades and plugins from existing 
>instances of a web application, but the process is going to 
>be fairly intensive, and I don't want it to get called too 
>often.
>
>Basically I need for it to be called any time the product 
>is refreshed or Zope restarted.  This means that it should
>get called on each instance whenever the source files
>are (re-)interpreted and imported.
>
>If I just put this into __setstate__, I'm afraid it will 
>get called rather more frequently than that, but I'm not 
>familiar enough with it to know how much of a problem 
>that's likely to be.  Obviously just using the __setstate__ 
>hook would be the easiest solution.
>
>Is there a better hook to use?
>
>If not, I had considered giving my class a class property 
>based on the date, and then checking that in __setstate__
>to determine if any further work should be done:
>
>class  MyClass(...):
>    import_date = DateTime()
>
>    def __init__(self, ...):
>        self.current_import_date = self.import_date
>
>    def __setstate__(self, state):
>        if self.import_date != self.current_import_date:
>            pass # Actually do my update work here
>            self.current_import_date = self.import_date
>
>In the absence of a standard solution, this seems like the 
>simplest approach.  Is this the way to go, or am I 
>overlooking some "batteries" somewhere?
>
>Obviously the idea is to allow my instances to take 
>advantage of newly installed plugins after a simple restart 
>or refresh instead of having to create new instances every 
>time something is changed (which would get to be a royal 
>PITA in production use).
>
>Cheers,
>Terry
>
>--
>Terry Hancock ( hancock at anansispaceworks.com )
>Anansi Spaceworks  http://www.anansispaceworks.com
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://mail.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
>
>  
>