On Nov 6, 2007, at 5:02 AM, Eric Bréhault wrote:


WIth Zope2, when I need to create or read a file in the filesystem, I usually go in /myzopeinstance/var directory
and to find it is pretty easy:
import os

But in Zope3, CLIENT_HOME or INSTANCE_HOME are no longer provided in os.environ

I had a look to different source code, and apparently the solution is to use the path of the current file to get the instance home, so we have code like this:
            os.path.join (os.path.dirname(__file__),
                         os.pardir, os.pardir, os.pardir, os.pardir))

Is there any easier (and cleaner) way to do it ?

Yes. If you want to have a directory like this:

- Create it (or arrange for it to be created lazily)

- Configure it in zope.conf:

    <product-config var>
         directory /location/of/directory

- To get this information from Python:

      import zope.app.appsetup.product
      var_dir = zope.app.appsetup.product['var']['directory']

As has been pointed out, there is no equivalent of an instance home in Zope 3, because we don't want to impose such a restrictive model, but you can easily provide such a model for yourself if you wish.


Jim Fulton
Zope Corporation

Zope3-users mailing list

Reply via email to