Commit ffe0f9f9 authored by Chris McDonough's avatar Chris McDonough

Add 'debug' and 'run' commands to zopectl.

parent 725a9822
......@@ -80,8 +80,9 @@ class ZopeCtlOptions(ZDOptions):
ZDOptions.realize(self, *args, **kw)
config = self.configroot
self.directory = config.instancehome
self.clienthome = config.clienthome
self.program = [os.path.join(self.directory, "bin", "runzope")]
self.sockname = os.path.join(config.clienthome, "zopectlsock")
self.sockname = os.path.join(self.clienthome, "zopectlsock")
self.user = None
self.python = sys.executable
self.zdrun = os.path.join(os.path.dirname(zdaemon.__file__),
......@@ -123,6 +124,41 @@ class ZopeCmd(ZDCmd):
os.putenv('ZMANAGED', '1')
ZDCmd.do_start(self, arg)
def get_startup_cmd(self, python, more):
cmdline = ( '%s -c "from Zope.Startup.options import ZopeOptions; '
'from Zope.Startup import handlers as h; '
'from App import config; '
'opts=ZopeOptions(); '
'opts.configfile=\'%s\'; '
'opts.realize(); '
'h.handleConfig(opts.configroot,opts.confighandlers);'
'config.setConfiguration(opts.configroot); ' %
(python, self.options.configfile)
)
return cmdline + more + '\"'
def do_debug( self, arg ):
cmdline = self.get_startup_cmd(self.options.python + ' -i',
'import Zope; app=Zope.app()')
print ('Starting debugger (the name "app" is bound to the top-level '
'Zope object)')
os.system(cmdline)
def help_debug(self):
print "debug -- run the Zope debugger to inspect your database"
print " manually using a Python interactive shell"
def do_run( self, arg ):
cmdline = self.get_startup_cmd(self.options.python,
'import Zope; app=Zope.app(); execfile(\'%s\')' % arg)
os.system(cmdline)
def help_run(self):
print "run <script> -- run a Python script with the Zope environment"
print " set up. The script can use the name 'app' to"
print " access the top-level Zope object"
def main(args=None):
# This is exactly like zdctl.main(), but uses ZopeCtlOptions and
# ZopeCmd instead of ZDCtlOptions and ZDCmd, so the default values
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment