| 1 | import os |
|---|
| 2 | import sys |
|---|
| 3 | import code |
|---|
| 4 | import zdaemon.zdctl |
|---|
| 5 | import zope.app.wsgi |
|---|
| 6 | import zope.app.debug |
|---|
| 7 | import sphinxdocs.wsgiapp |
|---|
| 8 | from paste.urlmap import URLMap |
|---|
| 9 | from sqlalchemy import create_engine |
|---|
| 10 | from gp.sqlcomments import comment |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | def 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 | |
|---|
| 38 | def 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 | |
|---|
| 50 | class 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 | |
|---|
| 59 | def zdaemon_controller(zdaemon_conf='zdaemon.conf'): |
|---|
| 60 | args = ['-C', zdaemon_conf] + sys.argv[1:] |
|---|
| 61 | zdaemon.zdctl.main(args, options=None, cmdclass=ControllerCommands) |
|---|