source: trunk/packages/invirt-web/code/invirt.fcgi @ 2742

Last change on this file since 2742 was 2742, checked in by price, 14 years ago

Fix format string usage.

  • Property svn:executable set to *
File size: 1.8 KB
RevLine 
[579]1#!/usr/bin/python
[2733]2"""Main FastCGI entry point for web interface"""
[2660]3
4import cherrypy
5import os
6import sys
7
[2733]8import main
9
[2660]10dev = False
11base_dir = os.path.dirname(__file__)
12
[2702]13def usage():
[2740]14    argv0_dir = os.path.dirname(sys.argv[0])
15    print >>sys.stderr, """%s <unauth|auth> [config]
[2702]16
17Run server as FastCGI, with CherryPy config from "main.conf".
18With `config`, run standalone with CherryPy config from `config`.
[2733]19
[2741]20Serve the authenticated or unauthenticated site according to
21the first argument.
22
23Helper scripts "auth.fcgi" and "unauth.fcgi" are provided to
24facilitate running the server with no arguments.
[2742]25""" % (sys.argv[0],)
[2702]26    sys.exit(2)
27
28if __name__ == "__main__":
[2741]29    if '-h' in sys.argv or '--help' in sys.argv:
[2702]30        usage()
[2741]31    if not (2 <= len(sys.argv) <= 3):
32        usage()
33
34    mode = sys.argv[1]
[2740]35    if len(sys.argv) == 3:
36        conf_file = sys.argv[2]
[2660]37        dev = True
38    else:
39        conf_file = os.path.join(base_dir, 'main.conf')
[2728]40
41    app_config = {
42        '/': {
43            'tools.invirtwebstate.on': True,
44            },
45        }
[2733]46
[2740]47    if mode.startswith('auth'):
[2734]48        root = main.InvirtWeb()
[2740]49        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache"
50    elif mode.startswith('unauth'):
[2734]51        root = main.InvirtUnauthWeb()
[2740]52        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache"
[2733]53    else:
54        usage()
55
56    app = cherrypy.tree.mount(root, '/', app_config)
[2729]57    app.merge(conf_file)
[2660]58    cherrypy.config.update(conf_file)
59
60    if dev:
61        cherrypy.server.quickstart()
62        cherrypy.engine.start()
63        cherrypy.engine.block()
64    else:
65        cherrypy.engine.start(blocking=False)
66        from flup.server.fcgi import WSGIServer
[2692]67        server = WSGIServer(cherrypy.tree)
[2660]68        server.run()
Note: See TracBrowser for help on using the repository browser.