[Zope] converting Python ap to Zope

Joachim Werner joe@iuveno-net.de
Sat, 1 Dec 2001 16:50:20 +0100


Hi!

I am a bit confused by your problems. Let's see what I can comment on ...

> I have tried loading the whole app as an external method, which didn't
> work, but I learned to make a copy of ALL modules and place them in a
> Zope sub-folder.  The python path from my stand-alone python 2.1 didn't
> get searched.

I'd definitely go with a Zope Product, not an External Method ...

If you configure your Zope right and actually make it use your standalone
Python instead of its own one, all the stuff in your Python path is fully
available. E.g., if you have installed PIL (Python Imaging Library), it is
available from your Zope Products via "import PIL" as usual.

> 1) There are a lot of classes and tables.  Each user can create multiple
> sets of the application classes and tables.  Each set of instances and
> attributes is pickled as a file.  The application is basically just a
> wrapper for the pickled instances.  I can think of no way to convert the
> pickle file into classes and attributes that Zope can see and/or modify.
> It seems I will have to re-factor each and every python class as a Zope
> class.

This irritates me most. If you have the ZODB, why would you want to do
pickling on your own? I guess some refactoring of the code and doing it the
Zope way would help a lot here. Even if you used Python standalone, using
the ZODB as a storage would be much more comfortable than pickling to files.

Basically, to move from a "normal" class to a persistent class, you'd just
have to import a few base classes (mainly "Persistent"). You won't have to
convert the data structures. Just rewrite the code a bit. Look at
http://www.zope.org/Documentation/ZDG/Persistence.stx for the details, if
you haven't already.

Another question: Are you talking about pickling instances of classes (which
is trivial in Zope) or classes themselves (which is currently impossible)?
In Zope, classes (except for ZClasses) are filesystem-based code, and
instances are in the ZODB (though instances are classes, too, if we want to
be syntactically correct).

> 2) several specialized data files are involved, which are opened and
> positioned based on the classes and parameters.  The files are needed
> for all aspects of the application.  Since Zope cannot pickle open file
> handles, I could store file names, positions, and other attributes, but
> I don't know how to re-open the files any time Zope restarts so that the
> user just references my object name (and methods) to access the data.



> 3) the key to accessing these specialized files is a windows .DLL file
> that works great in Python, but is unpickleable (is that a word?) in
> Zope.  I think I want to create a function that gets loaded when the
> Product does, but I cannot find any examples of Products that do this:
> allow instanciated objects to call custom functions created from
__init__.py in
> a Product.  There must be someplace to add globally available functions
> to Zope outside of ZODB, yes?

ALL the functions and methods defined in filesystem-based class definitions
are outside the ZODB. Let's take an example: If you have a user folder
implementation in Zope, the ZODB will only store the user info. All the
actual code, like the password validation, encryption etc. is outside the
ZODB of course.

Why would you want to pickle a .DLL file? Or did I get that wrong? Your
problem sounds a bit as if you wanted to store a full version of Word 2000
with every .doc file you create because you might need it the next time you
work with the document. But maybe I just don't get the point ...

Make sure that you really understand the concept of Persistence before you
go on. It is mainly about programming code as if it was running forever
(i.e. stateful), but actually Zope can store the state between the
(stateless) web requests.

Cheers

Joachim