[Zope-Checkins] CVS: Zope/lib/python/Controller - Directives.py:1.1.2.6 Main.py:1.1.2.10 ZctlLib.py:1.1.2.7
Chris McDonough
chrism@zope.com
Mon, 14 Oct 2002 02:33:03 -0400
Update of /cvs-repository/Zope/lib/python/Controller
In directory cvs.zope.org:/tmp/cvs-serv16813/lib/python/Controller
Modified Files:
Tag: chrism-install-branch
Directives.py Main.py ZctlLib.py
Log Message:
Move zope.py to SOFTWARE_HOME.
Make it possible to pass all directives on the command line to
zope.py as well as zctl.py.
=== Zope/lib/python/Controller/Directives.py 1.1.2.5 => 1.1.2.6 ===
--- Zope/lib/python/Controller/Directives.py:1.1.2.5 Fri Oct 11 14:34:34 2002
+++ Zope/lib/python/Controller/Directives.py Mon Oct 14 02:33:02 2002
@@ -74,23 +74,33 @@
for directive in self.directivesByPriority():
directive.activate()
- def reconfigure(self, config_filename):
+ def reconfigure(self, config_filename, overrides=None):
+ if overrides is None:
+ overrides = {}
self.resetDefaults()
self.location = config_filename
zconfig = ZConfig.load(filename2url(self.location))
+ # populate from config file first
for name, value in zconfig.items():
- directive = self._names[name][1]
+ directive = self.getDirective(name)
directive.set(value, zconfig)
+ # override with command-line specified directives
+ for name, value in overrides.items():
+ directive = self.getDirective(name)
+ directive.set(value, overrides)
self.activateDirectives()
def unregister(self, name):
- priority, directive = self._names[name][1]
+ priority, directive = self._names[name]
l = self._priorities[priority]
l.remove(name)
del self._names[name]
+ def getDirective(self, name):
+ return self._names[name][1]
+
def getDirectiveValue(self, name):
- return self._names[name][1].getValue()
+ return self.getDirective(name).getValue()
__getitem__ = getDirectiveValue
=== Zope/lib/python/Controller/Main.py 1.1.2.9 => 1.1.2.10 ===
--- Zope/lib/python/Controller/Main.py:1.1.2.9 Sat Oct 12 18:37:43 2002
+++ Zope/lib/python/Controller/Main.py Mon Oct 14 02:33:02 2002
@@ -18,11 +18,11 @@
from lock_file import lock_file
_marker = []
-def start_zope(config_location):
+def start_zope():
check_python_version()
# config *must* include zope_home, software_home and instance_home
+ # and caller *must* preregister directives
config = Directives.DirectiveRegistry
- config.reconfigure(config_location)
ZOPE_HOME = config['zope_home']
SOFTWARE_HOME = config['software_home']
INSTANCE_HOME = config['instance_home']
=== Zope/lib/python/Controller/ZctlLib.py 1.1.2.6 => 1.1.2.7 ===
--- Zope/lib/python/Controller/ZctlLib.py:1.1.2.6 Sat Oct 12 16:28:35 2002
+++ Zope/lib/python/Controller/ZctlLib.py Mon Oct 14 02:33:02 2002
@@ -27,7 +27,7 @@
CONFIG_LOCATION = config_location
ZOPE_HOME = zope_home
SOFTWARE_HOME = software_home
- ZOPE_PY_LOCATION = os.path.join(ZOPE_HOME, 'bin', 'zope.py')
+ ZOPE_PY_LOCATION = os.path.join(SOFTWARE_HOME, 'zope.py')
_ZopeCtlCmd().main()
import getopt, os, sys, re, signal, cmd, time
@@ -95,9 +95,9 @@
"""
Start the Zope appserver.
- Syntax: start [zope.py options]
+ Syntax: start [arg1, arg2, ..]
- All options are passed to the zope.py command line.
+ All arguments are passed to the zope.py command line.
"""
if self._getDirective('use_zeo_server'):
@@ -119,12 +119,12 @@
return
self._report('Starting Zope')
- args = self._getCommandLineArgs()
+ opts = self._getCommandLineOpts()
loc = CONFIG_LOCATION
if loc.find(' ') != -1:
loc = '"%s"' % loc
config_location = '--config-location=%s' % loc
- args = [ZOPE_PY_LOCATION] + [config_location] + args + [arg]
+ args = [ZOPE_PY_LOCATION] + [config_location] + opts + [arg]
wait = self._getDirective('debug_mode')
try:
apply(self._spawnPython, args, {'wait':wait})
@@ -276,15 +276,16 @@
Options:
- config Combo of 'directives', 'python', 'command-line',
- and 'config-path'
+ config Combo of 'directives', 'python', 'config-path' and
+ 'command-line'
+
+ command-line Command-line opts that will be passed to zope.py
+ when 'start' is invoked
directives All directive values
python Python version and path info
- command-line Full command-line to pass to zope.py
-
config-path Filename or url used to obtain config data.
"""
if type( what ) is type( '' ):
@@ -311,8 +312,8 @@
if whatsit.get( 'config' ):
whatsit[ 'directives' ] = 1
- whatsit[ 'python' ] = 1
whatsit[ 'command-line' ] = 1
+ whatsit[ 'python' ] = 1
whatsit[ 'config-path' ] = 1
for unk in unknown:
@@ -321,12 +322,12 @@
if whatsit.get( 'python' ):
self._showPython()
- if whatsit.get( 'command-line' ):
- self._showCommandLine()
-
if whatsit.get( 'config-path' ):
self._showConfigPath()
+ if whatsit.get( 'command-line' ):
+ self._showCommandLine()
+
if whatsit.get( 'directives' ):
self._showDirectives()
@@ -357,7 +358,7 @@
"""
Start a Python interpreter connected to the Zope appserver.
- Syntax: debug
+ Syntax: debug [directive1=value, directive2=value, ...]
"""
swhome = self._getSoftwareHome()
zopehome = self._getZopeHome()
@@ -407,6 +408,7 @@
#
# Helper functions
#
+
def _report( self, msg='', level=1 ):
msg = TextBlockFormatter.format(msg, max_width=73, indent=6)
self._reporter( msg, level )
@@ -438,13 +440,7 @@
def _setCommandLineOpts( self, l ):
self._cmdline = l
- def _buildCommandLine( self ):
- l = []
- for k,v in self._cmdline:
- l.append('%s=%s' % (k,v))
- return ' '.join(l)
-
- def _getCommandLineArgs(self):
+ def _getCommandLineOpts(self):
l = []
for k,v in self._cmdline:
l.append('%s=%s' % (k,v))
@@ -521,10 +517,6 @@
self._report( ' %s' % p )
self._report()
- def _showCommandLine( self ):
- self._report()
- self._report('zope.py command line: %s' % self._buildCommandLine())
-
def _showConfigPath( self ):
self._report()
self._report('Configuration Path: %s' % self._config.getLocation())
@@ -535,6 +527,12 @@
self._report()
printable = self._config.printable()
self._report( printable )
+
+ def _showCommandLine(self):
+ self._report()
+ self._report('Command Line:')
+ self._report()
+ self._report(' '.join(self._getCommandLineOpts()))
def lockFile(self):
filename = os.path.join(self._getLockfileName())
@@ -717,27 +715,38 @@
self._report( USAGE )
def main( self ):
+ overrides = {}
+ # add directives to options list
+ DirectiveRegistry.registerDefaults()
+ directives = DirectiveRegistry.namesByPriority()
+ longopts = [ "help", "config-location="]
+ for name in directives:
+ longopts.append('%s=' % name)
+
try:
- longopts = ['help', 'config-location=']
- o, a = getopt.getopt( sys.argv[1:], 'h', longopts)
+ opts, args = getopt.getopt(sys.argv[1:], "h", longopts)
except getopt.GetoptError, v:
print v
self.usage()
sys.exit(127)
-
- for k, v in o:
+ for k, v in opts:
if k in ('-h', '--help'):
self.usage()
sys.exit(0)
elif k == '--config-location':
- config_location = v
- reg = DirectiveRegistry
- reg.reconfigure(CONFIG_LOCATION)
- self._engine._setConfig(reg)
- self._engine._setCommandLineOpts(o)
- if a:
- self.cmdqueue.append( ' '.join( a ) )
- self.cmdqueue.append( 'EOF' )
+ global CONFIG_LOCATION
+ CONFIG_LOCATION = v
+ else:
+ if k.startswith('--'):
+ k = k[2:]
+ overrides[k] = v
+
+ DirectiveRegistry.reconfigure(CONFIG_LOCATION, overrides)
+ self._engine._setConfig(DirectiveRegistry)
+ self._engine._setCommandLineOpts(opts)
+ if args:
+ self.cmdqueue.append(' '.join(args))
+ self.cmdqueue.append('EOF')
self.cmdloop()