[Zope3-Users] Find the zope3 instance home directory (or the /var directory)

Jim Fulton jim at zope.com
Wed Nov 7 10:25:58 EST 2007


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

> Hello,
>
> 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
> os.environ['CLIENT_HOME']
>
> 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.normpath(
>             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
     <product-config>

- 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

--
Jim Fulton
Zope Corporation




More information about the Zope3-users mailing list