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

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

Fix format string usage.

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/python
2"""Main FastCGI entry point for web interface"""
3
4import cherrypy
5import os
6import sys
7
8import main
9
10dev = False
11base_dir = os.path.dirname(__file__)
12
13def usage():
14    argv0_dir = os.path.dirname(sys.argv[0])
15    print >>sys.stderr, """%s <unauth|auth> [config]
16
17Run server as FastCGI, with CherryPy config from "main.conf".
18With `config`, run standalone with CherryPy config from `config`.
19
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.
25""" % (sys.argv[0],)
26    sys.exit(2)
27
28if __name__ == "__main__":
29    if '-h' in sys.argv or '--help' in sys.argv:
30        usage()
31    if not (2 <= len(sys.argv) <= 3):
32        usage()
33
34    mode = sys.argv[1]
35    if len(sys.argv) == 3:
36        conf_file = sys.argv[2]
37        dev = True
38    else:
39        conf_file = os.path.join(base_dir, 'main.conf')
40
41    app_config = {
42        '/': {
43            'tools.invirtwebstate.on': True,
44            },
45        }
46
47    if mode.startswith('auth'):
48        root = main.InvirtWeb()
49        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache"
50    elif mode.startswith('unauth'):
51        root = main.InvirtUnauthWeb()
52        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache"
53    else:
54        usage()
55
56    app = cherrypy.tree.mount(root, '/', app_config)
57    app.merge(conf_file)
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
67        server = WSGIServer(cherrypy.tree)
68        server.run()
Note: See TracBrowser for help on using the repository browser.