#!/usr/bin/env python
import pkg_resources
pkg_resources.require("TurboGears")

import cherrypy
import turbogears
from os.path import *
from os import access, R_OK
import sys

# first use the app's configuration, then try the autogenerated
# one, if it exists, and the use the /etc file to override the
# configuration with the admin choices
turbogears.update_config(modulename="whatwhat.config.app")
for cfgfile in ["/var/cache/turbogears/whatwhat/prod.cfg",
                "/etc/turbogears/whatwhat/prod.cfg"]:
    if access (cfgfile, R_OK):
        turbogears.update_config (configfile=cfgfile,
                                  modulename="whatwhat.config")

if len(sys.argv) > 1:
    turbogears.update_config(configfile=sys.argv[1],
                                  modulename="whatwhat.config")

from whatwhat.controllers import Root

cherrypy.root = Root()
cherrypy.server.start()
