At 04:21 PM 1/4/02 -0500, Clark C . Evans wrote:
>ok.  I've spent some serious time learning how Python
>does modules, path, etc., and i have a few questions.
>Let's assume my layout looks like this...
>
>/product/V1/lib/tool.py
>/product/V1/app/a/apage.py
>/product/V1/app/b/apage.py
>
>/product/V2/lib/tool.py
>/product/V2/app/a/apage.py
>/product/V2/app/b/apage.py
>
>In my webware configuration, the two
>contexts are... /product/V1/app and
>/product/V2/app.
>
>The question is... how do I import tool.py
>from apage.py that is version dependent?
>I can reduce this problem to...
>
> From the module /V2/app/b/apage.py, how
>do I determine what context I'm in?
>
>I have a kludge.  I can introduce a semi-generic
>function  "loader" that I put into each directory
>(multiple copies of it).   This function then uses
>the __file__ segment do determine the context, and
>then this context can be used to return the
>appropriate tool module.   The solution works, but
>I don't like it.  Any other ideas?
>
>Best,
>
>Clark

So I assume the trouble arises because you don't want to have to hard-code 
"from V1.lib import tool" and "from V2.lib import tool" into the respective 
apage.py modules.

If so, then your kludge is the only way I can think of to do it.  You could 
add some symbolic links or maybe even play some clever tricks with 
tracebacks to make it slightly less kludgey.  What I'm thinking of is 
something like:

def whichContext():
         try:
                 1/0
         except:
                 # here you examine the traceback object to determine which 
context this was executed in

Or you could just save yourself the trouble and run separate copies of the 
appserver, which is what I'm doing.  I actually have about a dozen 
different versions of the appserver running on one machine right now 
(nightly builds from source control, plus a "deployed" version).


--

- Geoff Talvola
   [EMAIL PROTECTED]

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

Reply via email to