#!/usr/bin/env python

import pkg_resources
pkg_resources.require("TurboGears")
import asyncore
import cherrypy
import turbogears

from cherrypy._cpwsgi import wsgiApp
from scgi_server import SCGIServer

from os.path import *
import sys

turbogears.update_config(configfile="prod.cfg",
                         modulename="whatwhat.config.app")

port = 4000
if len(sys.argv) > 1:
    port = int(sys.argv[1])

from whatwhat.controllers import Root

cherrypy.root = Root()
cherrypy.server.start(initOnly=True, serverClass=None) 
server = SCGIServer(wsgiApp, '', host='localhost', port=port)
asyncore.loop()
