[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - run.py:1.1.2.2
zopectl.py:1.3.2.6
Chris McDonough
chrism at zopemafia.com
Sun Dec 21 19:24:56 EST 2003
Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv24011/lib/python/Zope/Startup
Modified Files:
Tag: Zope-2_7-branch
run.py zopectl.py
Log Message:
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.
=== Zope/lib/python/Zope/Startup/run.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/Zope/Startup/run.py:1.1.2.1 Mon Jul 21 12:37:47 2003
+++ Zope/lib/python/Zope/Startup/run.py Sun Dec 21 19:24:25 2003
@@ -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()
=== Zope/lib/python/Zope/Startup/zopectl.py 1.3.2.5 => 1.3.2.6 ===
--- Zope/lib/python/Zope/Startup/zopectl.py:1.3.2.5 Sat Aug 2 01:48:10 2003
+++ Zope/lib/python/Zope/Startup/zopectl.py Sun Dec 21 19:24:25 2003
@@ -134,16 +134,8 @@
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 + '\"'
More information about the Zope-Checkins
mailing list