Sasa,
I have used the approach you describe, but with a couple diffs:
* I make sure that the directory that contains Home.py and middle/ is in
sys.path. I do this in the __init__.py of my context. Something like:
def contextInitialize(app, ctxPath):
import os, sys
dirname = os.path.dirname
newPath = dirname(__file__)
if newPath not in sys.path:
sys.path.append(newPath)
Hmmm, I'm not sure why this uses __file__ instead of ctxPath, but I guess
either one works.
* And my real code (the above is a trimmed down snippet) is a little more
complex: it has to go back an extra dir. My structure is like this:
MyProject/
Web/
Pages/
__init__.py
MyPage.py
Utils/
SitePage.py
UserPage.py
Panel.py
Middle/
Thing.py
GeneratedPy/
...
The point here is that Pages/ is the context and everything that it uses
that is not public content is put outside so there is no danger in trying
to serve it via WebKit.
The reason my Middle/ is even higher up than what's in Web/ is that there
are other non-web applications using it. Otherwise, if it were strictly a
web project, Middle/ might have been put in Web/ (and Web/ renamed to
MyProject/).
* Another diff: The store creation is outside the middle/ directory, but
I'm not sure that has any affect on your situation. I would think it
wouldn't, but I just haven't tried it before.
Regarding '../../' working off of the cur process dir or the cur py module
dir, I didn't even know when I first tried this. Based on my experience,
though, it has to be the cur py module dir, because my app works fine and
the cur dir doesn't match up such that the imports would have worked.
Please try the tips above and let us know. If you confirm that they work,
then I will expand the MK docs.
-Chuck
At 01:39 PM 5/31/2001 +0000, Sasa Zivkov wrote:
>Hi,
>
>I used MiddleKit's Generate.py to generate "middle" objects from
>Videos.mkmodel example.
>In Settings.config I defined "Package" : "middle" to generate a package.
>And of course I created __init__.py into the package directory.
>
>This is my directory structure:
>./
>Home.py -- this is a servlet
>./middle
> __init__.py
> Videos.mkmodel/
> GeneratedPy/
> __init__.py
> GenMovie.py
> ...
> GeneratedSQL/
> ...
> Movie.py
> Video.py
> ...
>
>in ./middle/__init__.py I have:
>from MiddleKit.Run.MySQLObjectStore import MySQLObjectStore
>modelFile = ...
>store = MySQLObjectStore(user="sasha")
>store.readModelFileNamed(modelFile)
>
>in ./Home.py:
>from middle import store
>from middle.Movie import Movie # <=== and the problem starts HERE!!!
>
>When I try http://myhost/WK/MyContext I get exception:
>...
> File "/home/sasha/spuni/Home.py", line 4, in ?
> from middle.Movie import Movie
> File "/home/sasha/spuni/middle/Movie.py", line 6, in ?
> from GeneratedPy.GenMovie import GenMovie
> File "/home/sasha/spuni/middle/GeneratedPy/GenMovie.py", line 8, in ?
> from middle.Video import Video
>ImportError: No module named middle.Video
>
>Obviously GenMovie.py wants to import middle.Video but python can not find
>it in sys.path
>
>This is what I found in GenMovie.py:
>import sys
>sys.path.insert(0, '../../')
>from middle.Video import Video
>
>so it inserts '../../' in sys.path and tries to import middle.Video (because
>it is two levels up) but it fails.
>When you insert a relative path into sys.path is it relative to the current
>file or to the current directory ?
>It seems that it means relative to the current directory.
>
>Anybody of you generates middle objects as a package ?
>
>-- Sasa
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-discuss