import cherrypy
from cherrypy.process.plugins import (Daemonizer, PIDFile)

class RootServer:
    @cherrypy.expose
    def index(self, **keywords):
        import sys
        ret_path = "<br />\n".join(sys.path)
        return "%s\n" % ret_path

import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'server.conf')

if __name__ == '__main__':
    from optparse import OptionParser
    p = OptionParser()
    p.add_option('-d', '--daemon', action = "store_true", dest = "do_daemon")
    options, args = p.parse_args()
    if options.do_daemon:
        root_dir = os.path.dirname(os.path.abspath(__file__))
        Daemonizer(cherrypy.engine,
                   stdout="%s/log/access.log"%root_dir,
                   stderr="%s/log/error.log"%root_dir).subscribe()
        PIDFile(cherrypy.engine, "%s/pid"%root_dir).subscribe()
    cherrypy.quickstart(RootServer(), config=tutconf)