source: package_branches/invirt-web/cherrypy-rebased/code/invirt.fcgi @ 3003

Last change on this file since 3003 was 2739, checked in by quentin, 15 years ago

Properly separate the auth.fcgi and unauth.fcgi scripts

  • 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():
[2739]14    argv0_dir = os.path.dirname(sys.argv[0])
15    print >>sys.stderr, """%s <unauth|auth> [config]
16%s/auth.fcgi [config]
17%s/unauth.fcgi [config]
[2702]18
19Run server as FastCGI, with CherryPy config from "main.conf".
20
21With `config`, run standalone with CherryPy config from `config`.
[2733]22
23Run this script as either 'auth.fcgi' or 'unauth.fcgi', to get
[2739]24the authenticated or unauthenticated site respectively, or pass
25'auth' or 'unauth' as the first parameter.
26""" % (sys.argv[0], argv0_dir, argv0_dir)
[2702]27    sys.exit(2)
28
29if __name__ == "__main__":
[2739]30    if len(sys.argv) > 3 or len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv:
[2702]31        usage()
[2739]32    if len(sys.argv) == 3:
33        mode = sys.argv[1]
34        conf_file = sys.argv[2]
[2660]35        dev = True
36    else:
[2739]37        mode = sys.argv[1]
[2660]38        conf_file = os.path.join(base_dir, 'main.conf')
[2728]39
40    app_config = {
41        '/': {
42            'tools.invirtwebstate.on': True,
43            },
44        }
[2733]45
[2739]46    if mode.startswith('auth'):
[2734]47        root = main.InvirtWeb()
[2739]48        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache"
49    elif mode.startswith('unauth'):
[2734]50        root = main.InvirtUnauthWeb()
[2739]51        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache"
[2733]52    else:
53        usage()
54
55    app = cherrypy.tree.mount(root, '/', app_config)
[2729]56    app.merge(conf_file)
[2660]57    cherrypy.config.update(conf_file)
58
59    if dev:
60        cherrypy.server.quickstart()
61        cherrypy.engine.start()
62        cherrypy.engine.block()
63    else:
64        cherrypy.engine.start(blocking=False)
65        from flup.server.fcgi import WSGIServer
[2692]66        server = WSGIServer(cherrypy.tree)
[2660]67        server.run()
Note: See TracBrowser for help on using the repository browser.