I’m setting up a CherryPy application and would like to have the majority of my configuration settings in a .conf file like this:
[global]
server.socketPort = 8080
server.threadPool = 10
server.environment = "production"
However I would also like to setup a few with a dictionary in code like this:
conf = {'/': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(current_dir, 'templates')}}
cherrypy.quickstart(HelloWorld(), config=conf)
Is it possible to combine both configs into one and then pass it into the config quickstart option?
quickstartis for quick sites. If you’re doing anything as complex as having multiple configs, it’s time to graduate. Look at the source code for the quickstart function (it’s not scary!): you’re going to unpack that into your startup script. So instead ofquickstart, write this:We’ve essentially added two lines to the quickstart code. First, we have an extra call to
config.update; that merges the config dict into the global config. Second,app.merge(confdict); that’s for merging multiple configs into each app.It’s perfectly OK to do these in the opposite order if you want the file config to override the dict. It’s also OK to stick the dict-based config in
HelloWorld._cp_configas described in the docs.