CherryPy configuration tools.staticdir.root problem
Question: How can I make my static-file root directories relative to my application root
folder (instead of a hard-coded path)?

In accordance with CP instructions
(http://www.cherrypy.org/wiki/StaticContent) I have tried the following in my
configuration file:

    
    
    tree.cpapp = cherrypy.Application(cpapp.Root())
    tools.staticdir.root = cpapp.current_dir
    

but when I run `cherrpy.quickstart(rootclass, script_name='/',
config=config_file)` I get the following error

_builtins.ValueError: ("Config error in section: 'global', option:
'tree.cpapp', value: 'cherrypy.Application(cpapp.Root())'. Config values must
be valid Python.", 'TypeError', ("unrepr could not resolve the name
'cpapp'",))_

I know I can do configuration from within the main.py file just before
quickstart is called (eg. using os.path.abspath(os.path.dirname(**file**))),
but I prefer using the idea of a separate configuration file if possible.

Any help would be appreciated (in case it is relevant, I am using CP 3.2 with
Python 3.1)

TIA Alan


Answer: When you refer to a module inside configuration entries, CherryPy first looks
for that module in `sys.modules`. So one solution would be to `import cpapp`
just before you call quickstart.

But if that lookup in `sys.modules` fails, CherryPy tries to `__import__` the
module. Since that is also failing, you might need to investigate whether your
`cpapp.py` module is indeed importable at all.

See the `lib/reprconf.py` module for all the gory details.

