[Zope] Problem with external methods in ZOPE
Passin, Tom
tpassin at mitretek.org
Tue Sep 9 12:11:21 EDT 2003
[Miguel Garcia]
Hi, I'm New with Zope, and I need to make a external method to open a
file, search some things and return those values, I have the script
already make in Python. When I run in Python it runs fine, but when I
put it on the extension folder of Zope and added the external method in
the Zope folder where I need to start the search, this returrn an error
that say "
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: IOError
Error Value: [Errno 2] No such file or directory: 'chr1/CDS.htm'"
The external method is in a folder called database, inside that folder
are 14 folders called chr1, chr2, chr3 etc..., and inside any folder is
a DTML document called CDS.htm. Please help me with this because I don't
know what's the problem.
[Tom P]
The external method uses whatever default path is in effect when it is
called. Of course, it is not likely to be the path that you want. You
should not try to control that. Instead, you should make sure that your
data files are in a location known to the external method. BTW, the
external method would best be in the Extensions folder rather than some
subfolder.
There are several ways to get a known path. Here are some of them -
1) Hard code the path into the code. This is the least desirable
approach, because the code will break if you move the installation of
the data. But it may serve for testing purposes.
2) Put the path to the data into an environmental variable and read it
when your external method starts. This is better than 1), but not that
much, since somewhere you have remember to set that environmental
variable.
3) Put all your external method code into a folder somewhere outside of
the Zope installation, put it onto the Python path, and make it a Python
package. Change your external method so that it is just a stub that
calls the real code. The code in the package can find out its own
location (using the __file__ attribute). Put the data folders in a
known location relative to the package (maybe in subfolders), and use
os.path methods to construct the paths to the data files based on the
__file__ location.
I highly recommend 3). With this approach, the code automatically finds
its data no matter where the installation or code is moved to. You do
not have to remember to do anything to make this happen, it just works
automatically. As a byproduct, the Extensions folder remains simple and
uncluttered, which is a good thing, especially when you want to update
Zope.
The thing NOT to do is to change the current path, because you have no
idea what other bits of code may rely on the value of that path. They
should not, but you best not rely on that "should".
Cheers,
Tom P
More information about the Zope
mailing list