At 09:51 PM 10/26/2001 -0400, Clark C . Evans wrote:
>Ok.  I've graduated to a point where I need
>to have multiple directories in my source code,
>specifically, the following structure:
>
>/opt
>    /webware
>       /WebKit
>         (webkit files)
>/site
>    index.html    (what you see at http://mysite.com/WK/)
>    SitePage.py   (the base page for my site)
>    menu.py       (inherits from site page)
>    /appone
>       func.py    (inherits from SitePage.py)
>       boogle.py  (also inherits from SitePage.py)
>    /apptwo
>       func.py    (inherits from SitePage.py)
>       bongya.py  (also inherits from SitePage.py)
>
>Further, I've added an __init__.py to both
>/site/appone and /site/apptwo with the code:
>
>
>Questions:
>
>   1) In func.py I want to write
>      "from ../SitePage import SitePage"
>
>      This obviously won't work, which is why
>      I added an __init__.py to both /site/appone
>      and /site/apptwo with the following line:
>
>          import sys
>          sys.path.append('/site')
>
>      So that "from SitePage import SitePage"
>      will work in func.py and bongya.py
>
>      Is there a better way to do this?  Specifically,
>      I'd like to keep all of the path specific info
>      in the WebKit configuration file; but I didn't
>      see how I can do this.

I wanted this at first as well, but as you already noticed, Python does not 
make "import ../" very easy. And then Geoff and others convinced me that 
you don't want non-public files in your context. I agree and follow this 
style on all my sites:

appone/
         pages/
                 __init__.py
                 Main.py
                 Help.html
         lib/
                 __init__.py
                 SitePage.py

So then I do:
         from lib.SitePage import SitePage

This means no one can try to hack my site by running non-servlets or 
abstract servlets out of my context.

In the context's __init__.py I have to augment sys.path to know where lib 
is. This is something like:
         path = os.path.dirname(os.path.dirname(path))
         if path not in sys.path:
                 sys.path.insert(1, path)

You might have to fiddle with that a little, but you get the idea.


In my example, lib/ is under appone/ because I don't share very much 
between my apps (that isn't already in Webware). Obviously you could do it 
like this:

lib/
appone/
         context/
apptwo/
         context/

I often have other directories under my apps, like middle/ for MiddleKit 
objects, configs/ for config files, fragments/ for html fragements that get 
picked up by my servlets, and tests/ for regression test cases.


>   2) Is it a problem having two "func.py"?  It shouldn't
>      be, but I just wanted to check.

No, it shouldn't be. If there is, then it would be a bug.


-Chuck


_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to