root / www.gawel.org / trunk / src / wwwgawelorg / startup.py

Revision 1050, 2.2 kB (checked in by gawel, 2 months ago)

add fileupload deps

Line 
1import os
2import sys
3import code
4import zdaemon.zdctl
5import zope.app.wsgi
6import zope.app.debug
7import sphinxdocs.wsgiapp
8from paste.urlmap import URLMap
9from sqlalchemy import create_engine
10from gp.sqlcomments import comment
11
12
13def application_factory(global_conf, conf='zope.conf',
14                        comments='/tmp/comments',
15                        vhost='www.gawel.org',
16                        docs_root='',
17                        docs_path=''):
18    engine = create_engine('sqlite:///%s' % comments)
19    comment.initialize(engine)
20    zope_conf = os.path.join(global_conf['here'], conf)
21
22    zopeapp = zope.app.wsgi.getWSGIApplication(zope_conf)
23    vhost = '/++vh++http:%s:80/++' % vhost
24
25    def zopewrapper(environ, start_response):
26        environ['PATH_INFO'] = vhost + environ['PATH_INFO']
27        return zopeapp(environ, start_response)
28
29    docsapp = sphinxdocs.wsgiapp.make_app(global_conf,
30                                          root=docs_root,
31                                          path=docs_path)
32
33    app = URLMap({})
34    app['/docs/'] = docsapp
35    app['/'] = zopewrapper
36    return app
37
38def interactive_debug_prompt(zope_conf='zope.conf'):
39    db = zope.app.wsgi.config(zope_conf)
40    debugger = zope.app.debug.Debugger.fromDatabase(db)
41    # Invoke an interactive interpreter shell
42    banner = ("Welcome to the interactive debug prompt.\n"
43              "The 'root' variable contains the ZODB root folder.\n"
44              "The 'app' variable contains the Debugger, 'app.publish(path)' "
45              "simulates a request.")
46    code.interact(banner=banner, local={'debugger': debugger,
47                                        'app':      debugger,
48                                        'root':     debugger.root()})
49
50class ControllerCommands(zdaemon.zdctl.ZDCmd):
51
52    def do_debug(self, rest):
53        interactive_debug_prompt()
54
55    def help_debug(self):
56        print "debug -- Initialize the application, providing a debugger"
57        print "         object at an interactive Python prompt."
58
59def zdaemon_controller(zdaemon_conf='zdaemon.conf'):
60    args = ['-C', zdaemon_conf] + sys.argv[1:]
61    zdaemon.zdctl.main(args, options=None, cmdclass=ControllerCommands)
Note: See TracBrowser for help on using the browser.