*** lib/python/Zope/__init__.py.org	2004-05-17 12:41:29.000000000 -0400
--- lib/python/Zope/__init__.py	2004-05-17 14:09:21.000000000 -0400
***************
*** 33,38 ****
--- 33,40 ----
  # old behavior is likely to cause problems as ZODB backends, like ZEO,
  # gain new features.
  
+ from Zope.Startup.run import configure
+ 
  _began_startup = 0
  
  def startup():
***************
*** 47,52 ****
--- 49,55 ----
  
  def app(*args, **kw):
      """Utility for scripts to open a connection to the database"""
+     configure()
      startup()
      return bobo_application(*args, **kw)
  
***************
*** 56,63 ****
      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
  bobo_application = None
--- 59,64 ----
*** lib/python/Zope/Startup/run.py.org	2004-05-17 12:41:39.000000000 -0400
--- lib/python/Zope/Startup/run.py	2004-05-17 14:12:33.000000000 -0400
***************
*** 12,40 ****
  #
  ##############################################################################
  
  def run():
      """ 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 ZopeStarter
!     opts = _setconfig(configfile)
!     starter = ZopeStarter(opts.configroot)
!     starter.setupSecurityOptions()
!     starter.dropPrivileges()
  
  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()
      if configfile:
          opts.configfile=configfile
--- 12,45 ----
  #
  ##############################################################################
  
+ import App.config
+ 
  def run():
      """ Start a Zope instance """
      from Zope.Startup import start_zope
      opts = _setconfig()
      start_zope(opts.configroot)
  
! def configure(configfile=None):
      """ 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 ZopeStarter
!     if not App.config.isConfigured():
!         if not configfile:
!             import os
!             configfile = os.getenv("ZOPE_CONFIG")
!         opts = _setconfig(configfile)
!         starter = ZopeStarter(opts.configroot)
!         starter.setupSecurityOptions()
!         starter.dropPrivileges()
  
  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
      opts = options.ZopeOptions()
      if configfile:
          opts.configfile=configfile
***************
*** 43,49 ****
          opts.realize(doc="Sorry, no option docs yet.")
          
      handlers.handleConfig(opts.configroot, opts.confighandlers)
-     import App.config
      App.config.setConfiguration(opts.configroot)
      return opts
  
--- 48,53 ----
*** lib/python/App/config.py.org	2004-05-17 14:13:15.000000000 -0400
--- lib/python/App/config.py	2004-05-17 14:03:50.000000000 -0400
***************
*** 22,27 ****
--- 22,31 ----
  
  _config = None
  
+ def isConfigured():
+     """check to see if the app has been configured yet"""
+     return _config != None
+ 
  def getConfiguration():
      """Return the global Zope configuration object.
  
