[Zope-dev] Product directory?

2004-03-09 Thread Ian Beatty
Greetings again.

This has to be an easy one.

From within my Python-based product's code, how do I get access to the
product's directory on the filesystem? os.getcwd() seems to provide the
working directory of the shell used to launch Zope, at least when running in
debug mode.

I've tried ferreting it out from the source to DTMLFile and etc., but I
can't trace it.

Thanks,

..Ian

-- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- --
Dr. Ian Beatty   [EMAIL PROTECTED]
Physics Education Research Group  voice: 413.545.9483
Department of Physics   fax: 413.545.4884
Univ. of Massachusetts  AIM: (available upon request)
Amherst, MA 01003-4525 USA   http://umperg.physics.umass.edu/
-- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- --



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Product directory?

2004-03-09 Thread Andreas Kostyrka
On Tue, Mar 09, 2004 at 01:58:17PM -0500, Ian Beatty wrote:
 Greetings again.
 
 This has to be an easy one.
 
 From within my Python-based product's code, how do I get access to the
 product's directory on the filesystem? os.getcwd() seems to provide the
 working directory of the shell used to launch Zope, at least when running in
 debug mode.
Try os.path.dirname(mymodule.__file__)?

Andreas

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Product directory?

2004-03-09 Thread Fred Drake
On Tuesday 09 March 2004 01:58 pm, Ian Beatty wrote:
  This has to be an easy one.

Good, I'll take it.  ;-)

  From within my Python-based product's code, how do I get access to the
  product's directory on the filesystem? os.getcwd() seems to provide the
  working directory of the shell used to launch Zope, at least when running
  in debug mode.

This isn't actually Zope specific; you can easily get the directory a module 
lives in using this:

import os
here = os.path.dirname(os.path.abspath(__file__))

The variable here will hold a string with an absolute path to the directory 
containing the source file for your module (named by __file__).  The call to 
os.path.abspath() isn't strictly necessary, but protects against future calls 
to os.chdir() (though not past calls!) in case the module was loaded from 
directory named by a relative directory on sys.path.

You can do this just once at module scope; there's no need to recompute this 
each time you need it.


  -Fred

-- 
Fred L. Drake, Jr.  fred at zope.com
PythonLabs at Zope Corporation


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Product directory?

2004-03-09 Thread Fred Drake
On Tuesday 09 March 2004 02:30 pm, Chris McDonough wrote:
  There is also a convenience function for this in Zope:
 
  from Globals import package_home
  here = package_home(globals())

Maybe I'm just weird, but I generally prefer the general approach when there's 
not a clear improvement in readability or brevity.

Globals.package_home() is definately a more complicated approach to digging 
out the same information; it might be better for older versions of Python.  
It's not available in Zope 3.


  -Fred

-- 
Fred L. Drake, Jr.  fred at zope.com
PythonLabs at Zope Corporation


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )