views:

25

answers:

1

Both the Python logging module and CherryPy's Config API use ConfigParser files. Therefore, I assumed that I could use one single config file for my own applications configuration, it's logging configuration, and CherryPy's configuration.

When my logging and CherryPy were separate, they worked fine, and my config file does parse with no errors using the ConfigParser api. However, CherryPy seems to barf on this section:

[loggers]
keys=root,myapp,cherrypy,cperror,cpaccess

giving the following exception:

Traceback (most recent call last):
  File "/usr/lib/python2.6/multiprocessing/process.py", line 232, in _bootstrap
    self.run()
  File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
  File "unittests.py", line 431, in main
    cherrypy.config.update(server.CONFIG_FILE)
  File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 263, in update
    config = _Parser().dict_from_file(config)
  File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 383, in dict_from_file
    return self.as_dict()
  File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 374, in as_dict
    raise ValueError(msg, x.__class__.__name__, x.args)
ValueError: ("Config error in section: 'loggers', option: 'keys', value: 'root,myapp,cherrypy,cperror,cpaccess'. Config values must be valid Python.", 'TypeError', ("unrepr could not resolve the name 'root'",))

The CherryPy docs never say that CherryPy needs its config file to be separate from your other configuration, but I'm beginning to think that this might be necessary. The docs say that site and app configuration might need to be separate if you have more than one app per site, but that seems like a different issue... is it mistaking my logging configuration for a CherryPy app configuration?

Is this possible? If not, then I'm unsure why CherryPy even bothers using the ConfigParser library in the first place.

+1  A: 

Short answer: no, you probably cannot mix them. As described in the docs: "Config entries are always a key/value pair, like server.socket_port = 8080. The key is always a name, and the value is always a Python object. That is, if the value you are setting is an int (or other number), it needs to look like a Python int; for example, 8080. If the value is a string, it needs to be quoted, just like a Python string."

Even though we want arbitrary Python types in our CherryPy config values, CherryPy uses the ConfigParser simply because we didn't want to write our own parser for the section and entry syntax.

fumanchu