Christopher Arndt wrote:
> Jim Steil schrieb:
>
>> My question is how can I find
>> the top level directory of my TG app when I'm running this program.
>>
>> How do others handle this type of situation?
>>
>
> I see two possibilities:
>
> a) Use the turbogears config module:
>
> 1) Parse your TG application's config file:
>
> import turbogears
> turbogears.update_config(configfile='/path/to/config/file.cfg',
> modulename="mypackage.config")
>
> 2) Find out the path that corresponds to the "/static" URL:
>
> self.img_dir = os.path.join(
> turbogears.config.get('static_filter.dir', path="/static"), 'images')
>
> b) Use the "pkg_resources" module from the setuptools package to find the
> "static" subdirectory of your TG app's package dir:
>
> import pkg_resources
> static_dir = pkg_resources.resource_filename("mypackage", "static")
> img_dir = os.path.join(static_dir, 'images')
>
> Beware that both methods will fail, if you installed your TG app as a zipped
> EGG.
>
>
> Chris
>
>
> >
>
Chris: A couple of questions. First, for solution a, it appears as
though I'd need to know the path to my config file to implement step 1.
I don't think that would work for me because if I knew that path, I
could figure out the image path. Please correct me if my assumption is
incorrect. For option b, this works great when running under
TurboGears, but I received an error on line 2 when I ran it in a bare
Python shell with the following error:
static_dir = pkg_resources.resource_filename("motion", "static")
ImportError: No module named motion
I used the previous suggestion offered by David and it is working fine
under both of the necessary scenarios. Dave, thanks for pointing me in
that direction.
-Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---