Fix 'buildout.cfg' modification code
[zope-bootstrap.git] / skel-zope3 / src / appmain / startup.py
1 import os
2 import sys
3 import code
4 import zdaemon.zdctl
5 import zope.app.wsgi
6 import zope.app.debug
7
8 def application_factory(global_conf, conf='zope.conf'):
9     zope_conf = os.path.join(global_conf['here'], conf)
10     return zope.app.wsgi.getWSGIApplication(zope_conf)
11
12 def interactive_debug_prompt(zope_conf='zope.conf'):
13     db = zope.app.wsgi.config(zope_conf)
14     debugger = zope.app.debug.Debugger.fromDatabase(db)
15     # Invoke an interactive interpreter shell
16     banner = ("Welcome to the interactive debug prompt.\n"
17               "The 'root' variable contains the ZODB root folder.\n"
18               "The 'app' variable contains the Debugger, 'app.publish(path)' "
19               "simulates a request.")
20     code.interact(banner=banner, local={'debugger': debugger,
21                                         'app':      debugger,
22                                         'root':     debugger.root()})
23
24 class ControllerCommands(zdaemon.zdctl.ZDCmd):
25
26     def do_debug(self, rest):
27         interactive_debug_prompt()
28
29     def help_debug(self):
30         print "debug -- Initialize the application, providing a debugger"
31         print "         object at an interactive Python prompt."
32
33 def zdaemon_controller(zdaemon_conf='zdaemon.conf'):
34     args = ['-C', zdaemon_conf] + sys.argv[1:]
35     zdaemon.zdctl.main(args, options=None, cmdclass=ControllerCommands)