[Zope] Product module reloading

Michel Pelletier michel@digicool.com
Thu, 16 Sep 1999 13:38:04 -0400


> -----Original Message-----
> From: Sean Treadway [mailto:seant@factory.dk]
> Sent: Thursday, September 16, 1999 12:34 PM
> To: Kevin Dangoor
> Cc: Zope List
> Subject: Re: [Zope] Product module reloading
> 
> 
> Kevin Dangoor wrote:
> > In there, I think DC recommends developing your class logic 
> from within
> > python (not through the web, initially), because you don't 
> need to worry
> > about restarting servers, etc.
> 
> Yes, I would much rather debug outside of the web server but I do not
> have much experience with python (this product is also an endevor to
> bone up on python).  When I load my product's __init__.py or most any
> other module that imports Globals from the cmd line, I get get the
> following:
> 
> [seant@ember Product]$ python __init__.py
> Traceback (innermost last):
> ImportError: cannot import name Persistent
> 
> There is nothing defined in the module Persistence which 
> makes me wonder
> a bit about what is going on.  My PYTHONPATH includes
> .../zope/lib/python and I am running the python binary from a 1.5.2
> installation rather than the Zope installation.

Zope products depend on a lot of infrastructure to work.  You must
import Zope first in order to use them from Python.

[michel@korak python]$ python1.5.2
Python 1.5.2 (#1, Jul  5 1999, 14:47:37)  [GCC egcs-2.91.66
19990314/Linux (egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Py$ import Zope
Py$ import Products.ZCatalog
Py$ 

If you import 'Zope' first, your product will work.  The Persistence
module doesn't contain anything because it is populated with ZODB2 or
ZODB3 specific code upon startup (note, Zope does not come with ZODB2
anymore, but this is still done for future compatability with ZODB4, if
such a beast ever rears its head).

Note that there is lots of cool stuff that can be done from python:

Py$ root_folder=Zope.app()

Zope.app() creates a database connection and returns you the top level
Zope object.

Py$ root_folder.Catalog
<ZCatalog instance at 85eb950>

Here you can see we have a ZCatalog with the id 'Catalog' in the root
folder.

Py$ import ZPublisher

ZPublisher lets you simulate web requests:

Py$ ZPublisher.Zope('Catalog/manage', u='superuser:123')
Status: 200 OK
X-Powered-By: Zope (www.zope.org), Python (www.python.org)
Content-Length: 637
Content-Type: text/html

<HTML>
... managment frames...
</HTML>


____________________________________________________________

Py$ 


-Michel