Commit d1c9a710 authored by Chris McDonough's avatar Chris McDonough

Created 'configure' API function. The 'configure' API function accepts a config

file path and does for scripts what "start_zope" does for interactive startup.

Use the configure function from within zopectl, replacing some gnarly exec'd code.
parent 969753a7
......@@ -12,16 +12,38 @@
#
##############################################################################
# this function will actually start up a Zope instance
def run():
import App.config
from Zope.Startup import handlers, options, start_zope
""" Start a Zope instance """
from Zope.Startup import start_zope
opts = _setconfig()
start_zope(opts.configroot)
def configure(configfile):
""" Provide an API which allows scripts like zopectl to configure
Zope before attempting to do 'app = Zope.app(). Should be used as
follows: from Zope.Startup.run import configure;
configure('/path/to/configfile'); import Zope; app = Zope.app() """
from Zope.Startup import dropPrivileges
opts = _setconfig(configfile)
dropPrivileges(opts.configroot)
def _setconfig(configfile=None):
""" Configure a Zope instance based on ZopeOptions. Optionally
accept a configfile argument (string path) in order to specify
where the configuration file exists. """
from Zope.Startup import options, handlers
from App import config
opts = options.ZopeOptions()
opts.realize(doc="Sorry, no option docs yet.")
if configfile:
opts.configfile=configfile
opts.realize(doc="Sorry, no option docs yet.", raise_getopt_errs=0)
else:
opts.realize(doc="Sorry, no option docs yet.")
handlers.handleConfig(opts.configroot, opts.confighandlers)
import App.config
App.config.setConfiguration(opts.configroot)
start_zope(opts.configroot)
return opts
if __name__ == '__main__':
run()
......
......@@ -134,16 +134,8 @@ class ZopeCmd(ZDCmd):
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); '
'from Zope.Startup import dropPrivileges; '
'dropPrivileges(opts.configroot); '%
cmdline = ( '%s -c "from Zope import configure;'
'configure(\'%s\');' %
(python, self.options.configfile)
)
return cmdline + more + '\"'
......
......@@ -56,6 +56,7 @@ def debug(*args, **kw):
import ZPublisher
return ZPublisher.test('Zope', *args, **kw)
from Zope.Startup.run import configure
# Zope.App.startup.startup() sets the following variables in this module.
DB = None
......
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