[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - __init__.py:1.1.2.3 cmdline.py:1.1.2.2 datatypes.py:1.1.2.4 zopeschema.xml:1.1.2.9 logger.xml:NONE
Fred L. Drake, Jr.
fred@zope.com
Fri, 24 Jan 2003 18:28:53 -0500
Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv746
Modified Files:
Tag: chrism-install-branch
__init__.py cmdline.py datatypes.py zopeschema.xml
Removed Files:
Tag: chrism-install-branch
logger.xml
Log Message:
Lots of changes, including lots of dead code removal.
=== Zope/lib/python/Zope/Startup/__init__.py 1.1.2.2 => 1.1.2.3 ===
--- Zope/lib/python/Zope/Startup/__init__.py:1.1.2.2 Tue Jan 14 22:39:05 2003
+++ Zope/lib/python/Zope/Startup/__init__.py Fri Jan 24 18:28:49 2003
@@ -4,39 +4,39 @@
import sys
import socket
import re
-import types
-from ZConfig import ConfigurationError
-from ZConfig import loadSchema, loadConfig
+import ZConfig
+
from misc.lock_file import lock_file
-from cmdline import getOptions, getOptionDescriptions
+from cmdline import getOptions # exported
-# global to hold config structure
+# global to hold config structures
+_schema = None
_configuration = None
def getConfiguration():
return _configuration
-def getSchemaLocation():
- here = os.path.dirname(__file__)
- schema = os.path.join(here, 'zopeschema.xml')
- return schema
+def getSchema():
+ global _schema
+ if _schema is None:
+ here = os.path.dirname(__file__)
+ path = os.path.join(here, 'zopeschema.xml')
+ _schema = ZConfig.loadSchema(path)
+ return _schema
def getSchemaKeys():
- f = getSchemaLocation()
- schema = loadSchema(f)
+ schema = getSchema()
return schema.getchildnames()
def configure(config_location, options):
- f = getSchemaLocation()
- schema = loadSchema(f)
+ global _configuration
import handlers
- config, handler = loadConfig(schema, config_location)
+ schema = getSchema()
+ _configuration, handler = ZConfig.loadConfig(schema, config_location)
handlers.handleConfig(config, handler, options)
- global _configuration
- _configuration = config
return _configuration
-
+
def start_zope(config_location, options):
# caller must set configuration
check_python_version()
@@ -57,7 +57,7 @@
# don't initialize the event logger from the environment
zLOG._call_initialize = 0
import logging
-
+
from zLOG.LogHandlers import StartupHandler
# we log events to the root logger, which is backed by a
@@ -119,7 +119,7 @@
try:
server()
except socket.error:
- raise ConfigurationError(socket_err % server_type)
+ raise ZConfig.ConfigurationError(socket_err % server_type)
# do stuff that only applies to posix platforms (setuid, daemonizing)
if os.name == 'posix':
@@ -139,8 +139,8 @@
# if we can't lock it.
# we need a separate lock file because on win32, locks are not
# advisory, otherwise we would just use the pid file
- lock_filename = (cfg.lock_filename or
- os.path.join(cfg.instance_home,'var', 'Z2.lock'))
+ lock_filename = (cfg.lock_filename or
+ os.path.join(cfg.instance_home, 'var', 'Z2.lock'))
try:
if os.path.exists(lock_filename):
@@ -149,7 +149,7 @@
lock_file(LOCK_FILE)
except IOError:
pass
-
+
# write pid file if zdaemon didn't do it already
if not cfg.use_daemon_process:
pf = open(cfg.pid_filename, 'w')
@@ -160,13 +160,15 @@
# now that we've successfully setuid'd, we can log to
# somewhere other than stderr. We rely on config
# to set up our logging properly.
- for logger_name in ('event', 'access', 'trace'):
- factory = getattr(cfg, logger_name, None)
+ for logger_name in ('access', 'trace'):
+ factory = getattr(cfg, logger_name)
if factory:
logger = factory() # activate the logger
- # flush buffered startup messages to event logger
- if logger_name == 'event':
- startup_handler.flushBufferTo(logger)
+
+ # flush buffered startup messages to event logger
+ if cfg.eventlog:
+ logger = cfg.eventlog()
+ startup_handler.flushBufferTo(logger)
event_logger.removeHandler(startup_handler)
@@ -198,16 +200,11 @@
def check_python_version():
# check for Python version
- # too chicken to preclude 2.1 yet
python_version = sys.version.split()[0]
optimum_version = '2.2.2'
- if python_version < '2.1':
- raise ConfigurationError, 'Invalid python version %s' % python_version
- if python_version[:3] == '2.1':
- err = ('You are running Python version %s. Zope may work under this '
- 'Python version, but it may not. Consider upgrading to '
- 'Python %s\n' % (python_version, optimum_version))
- sys.stderr.write(err)
+ if python_version < '2.2':
+ raise ZConfig.ConfigurationError(
+ 'Invalid python version ' + python_version)
if python_version[:3] == '2.2':
if python_version[4:5] < '2':
err = ('You are running Python version %s. This Python version '
@@ -237,7 +234,7 @@
'start as root (change the effective_user directive '
'in zope.conf)')
zLOG.LOG('Zope', zLOG.PANIC, msg)
- raise ConfigurationError, msg
+ raise ZConfig.ConfigurationError(msg)
# stuff about client home faults removed (real effective user
# support now)
try:
@@ -245,16 +242,16 @@
except (TypeError, ValueError):
pass
gid = None
- if isinstance(UID, types.StringType):
+ if isinstance(UID, str):
uid = pwd.getpwnam(UID)[2]
gid = pwd.getpwnam(UID)[3]
- elif isinstance(UID, types.IntType):
+ elif isinstance(UID, int):
uid = pwd.getpwuid(UID)[2]
gid = pwd.getpwuid(UID)[3]
UID = pwd.getpwuid(UID)[0]
else:
zLOG.LOG("Zope", zLOG.ERROR, ("Can't find UID %s" % UID))
- raise ConfigurationError, 'Cant find UID %s' % UID
+ raise ZConfig.ConfigurationError('Cant find UID %s' % UID)
if UID == 'nobody':
_warn_nobody()
if gid is not None:
@@ -300,7 +297,7 @@
try:
import locale
except:
- raise ConfigurationError, (
+ raise ZConfig.ConfigurationError(
'The locale module could not be imported.\n'
'To use localization options, you must ensure\n'
'that the locale module is compiled into your\n'
@@ -309,10 +306,10 @@
try:
locale.setlocale(locale.LC_ALL, locale_id)
except:
- raise ConfigurationError, (
+ raise ZConfig.ConfigurationError(
'The specified locale "%s" is not supported by your system.\n'
'See your operating system documentation for more\n'
'information on locale support.' % locale_id
)
-
+
=== Zope/lib/python/Zope/Startup/cmdline.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/Zope/Startup/cmdline.py:1.1.2.1 Tue Jan 14 22:39:05 2003
+++ Zope/lib/python/Zope/Startup/cmdline.py Fri Jan 24 18:28:49 2003
@@ -99,45 +99,38 @@
handler(v)
cfg.use_daemon_process = v
elif k in ('-t', '--zserver-threads'):
- datatype = int
- v = datatype(v)
- cfg.zserver_threads = v
+ cfg.zserver_threads = int(v)
elif k in ('-i', '--python-check-interval'):
- datatype = int
- v = datatype(v)
- cfg.python_check_interval = v
+ cfg.python_check_interval = int(v)
elif k in ('-D', '--debug-mode'):
datatype = ZConfig.datatypes.asBoolean
- handler = Zope.Startup.handlers.debug_mode
+ handler = Zope.Startup.handlers.debug_mode
v = datatype(v)
handler(v)
cfg.debug_mode = v
elif k in ('-i', '--ip-address'):
datatype = ZConfig.datatypes.IpaddrOrHostname()
- v = datatype(v)
- cfg.ip_address = v
+ cfg.ip_address = datatype(v)
elif k in ('-d', '--dns-ip-address'):
datatype = ZConfig.datatypes.IpaddrOrHostname()
- v = datatype(v)
- cfg.dns_ip_address = v
+ cfg.dns_ip_address = datatype(v)
elif k in ('-u', '--effective-user'):
cfg.effective_user = v
elif k in ('-L', '--locale'):
datatype = ZConfig.datatypes.check_locale
- v = datatype(v)
- cfg.locale = v
+ cfg.locale = datatype(v)
elif k in ('-l', '--access-log'):
cfg.access = default_logger('access', v,
'%(message)s',
'%Y-%m-%dT%H:%M:%S')
elif k in ('-M', '--trace-log'):
cfg.trace = default_logger('trace', v,
- '%(message)s',
- '%Y-%m-%dT%H:%M:%S')
+ '%(message)s',
+ '%Y-%m-%dT%H:%M:%S')
elif k in ('-E', '--event-log'):
cfg.trace = default_logger('event', v,
- '------\n%(asctime)s %(message)s',
- '%Y-%m-%dT%H:%M:%S')
+ '------\n%(asctime)s %(message)s',
+ '%Y-%m-%dT%H:%M:%S')
elif k in ('-X', '--disable-servers'):
cfg.servers = []
else:
=== Zope/lib/python/Zope/Startup/datatypes.py 1.1.2.3 => 1.1.2.4 ===
--- Zope/lib/python/Zope/Startup/datatypes.py:1.1.2.3 Mon Jan 13 14:28:40 2003
+++ Zope/lib/python/Zope/Startup/datatypes.py Fri Jan 24 18:28:49 2003
@@ -1,3 +1,5 @@
+import os
+
from misc.factory import Factory
# generic datatypes
@@ -12,209 +14,15 @@
return value
def use_daemon_process(value):
- import os
from ZConfig.datatypes import asBoolean
+ daemonize = asBoolean(value)
# cannot use daemon process on non-POSIX platforms
if os.name != 'posix':
return False
- return asBoolean(value)
+ return daemonize
# log-related datatypes
-
-def log_format(value):
- d = {
- 'name':'',
- 'levelno':'3',
- 'levelname':'DEBUG',
- 'pathname':'apath',
- 'filename':'afile',
- 'module':'amodule',
- 'lineno':1,
- 'created':1.1,
- 'asctime':'atime',
- 'msecs':1,
- 'relativeCreated':1,
- 'thread':1,
- 'message':'amessage',
- }
- try:
- value % d
- except (ValueError, KeyError):
- raise ValueError, 'Invalid log format string %s' % value
- value = ctrl_char_insert(value)
- return value
-
-def ctrl_char_insert(value):
- chars = {r'\n':'\n', r'\t':'\t', r'\b':'\b', r'\f':'\f', r'\r':'\r'}
- realvalue = value
- for char in chars.keys():
- l = realvalue.split(char)
- realvalue = chars[char].join(l)
- return realvalue
-
-def file_handler(section):
- file = section.file
- format = section.format
- dateformat = section.dateformat
- level = section.level
-
- formatter = Factory('logging.Formatter', None, format, dateformat)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- return Factory('zLOG.LogHandlers.FileHandler', callback, file)
-
-def syslog_facility(value):
- d = {
- "auth":1,
- "authpriv":1,
- "cron":1,
- "daemon":1,
- "kern":1,
- "lpr":1,
- "mail":1,
- "news":1,
- "security":1,
- "syslog":1,
- "user":1,
- "uucp":1,
- "local0":1,
- "local1":1,
- "local2":1,
- "local3":1,
- "local4":1,
- "local5":1,
- "local6":1,
- "local7":1,
- }
- value = value.lower()
- if not d.has_key(value):
- raise ValueError, "Syslog facility must be one of %s" % d.keys()
- return value
-
-def syslog_handler(section):
- facility = section.facility
- socket = section.socket
- host = section.host
- port = section.port
- format = section.format
- dateformat = section.dateformat
- level = section.level
-
- if socket and host:
- raise ValueError, ('Only one of "socket" or "host" may be '
- 'specified in a syslog_handler section')
- if not (socket or host):
- raise ValueError, ('One of "socket" or "host" must be '
- 'specified in a syslog_handler section')
-
- formatter = Factory('logging.Formatter', None, format, dateformat)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- klass = 'zLOG.LogHandlers.SysLogHandler'
- if socket:
- handler = Factory(klass, callback, socket, facility)
- else:
- handler = Factory(klass, callback, (host, port), facility)
-
- return handler
-
-def nteventlog_handler(section):
- appname = section.appname
- format = section.format
- dateformat = section.dateformat
- level = section.level
-
- formatter = Factory('logging.Formatter', None, format, dateformat)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- return Factory('zLOG.LogHandlers.NTEventLogHandler', callback, appname)
-
-def http_handler_url(value):
- import urlparse
- scheme, netloc, path, query, fragment = urlparse.urlsplit(value)
- if scheme != 'http':
- raise ValueError, 'url must be an http url'
- if not netloc:
- raise ValueError, 'url must specify a location'
- if not path:
- raise ValueError, 'url must specify a path'
- q = []
- if query:
- q.append('?')
- q.append(query)
- if fragment:
- q.append('#')
- q.append(fragment)
- return (netloc, path + ''.join(q))
-
-def get_or_post(value):
- value = value.upper()
- if value not in ('GET', 'POST'):
- raise ValueError, ('method must be "GET" or "POST", instead received '
- '%s' % value)
- return value
-
-def http_handler(section):
- host, url = section.url
- method = section.method
- format = section.format
- dateformat = section.dateformat
- level = section.level
-
- formatter = Factory('logging.Formatter', None, format, dateformat)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- return Factory('zLOG.LogHandlers.HTTPHandler', callback, host, url, method)
-
-def smtp_handler(section):
- fromaddr = section.fromaddr
- toaddrs = section.toaddrs
- subject = section.subject
- host, port = section.host
- format = section.format
- dateformat = section.dateformat
- level = section.level
-
- if not port:
- mailhost = host
- else:
- mailhost = host, port
- formatter = Factory('logging.Formatter', None, format, dateformat)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- return Factory('zLOG.LogHandlers.SMTPHandler', callback,
- mailhost, fromaddr, toaddrs, subject)
-
-def null_handler(section):
- return Factory('zLOG.LogHandlers.NullHandler', None)
-
-def custom_handler(section):
- formatter_klass, formatter_pos, formatter_kw = section.formatter
- handler_klass, handler_pos, handler_kw = section.constructor
- level = section.level
-
- formatter = Factory(formatter_klass, None, formatter_pos, formatter_kw)
-
- def callback(inst, formatter=formatter, level=level):
- inst.setFormatter(formatter())
- inst.setLevel(level)
-
- return Factory(handler_klass, callback, *handler_pos, **handler_kw)
+# (the loghandler datatypes come from the zLOG package)
def logger(section):
return LoggerWrapper(section.getSectionName(),
@@ -279,7 +87,7 @@
}
return Factory('ZEO.ClientStorage.ClientStorage', None, addr, **kw)
-_marker = []
+_marker = object()
class LoggerWrapper:
"""
@@ -305,7 +113,7 @@
logger.propagate = 0
logger.setLevel(self.level)
for handler_factory in self.handler_factories:
- handler = handler_factory()
+ handler = handler_factory()
logger.addHandler(handler)
self.resolved = logger
return self.resolved
=== Zope/lib/python/Zope/Startup/zopeschema.xml 1.1.2.8 => 1.1.2.9 ===
--- Zope/lib/python/Zope/Startup/zopeschema.xml:1.1.2.8 Mon Jan 13 20:12:56 2003
+++ Zope/lib/python/Zope/Startup/zopeschema.xml Fri Jan 24 18:28:49 2003
@@ -2,7 +2,7 @@
<!-- type definitions -->
- <import src="logger.xml"/>
+ <import package="zLOG"/>
<abstracttype name="server"/>
@@ -46,6 +46,19 @@
</sectiontype>
+ <sectiontype name="logger" datatype=".logger">
+ <description>
+ This "logger" type only applies to access and request ("trace")
+ logging; event logging is handled by the zLOG package, which
+ provides the loghandler type used here.
+ </description>
+ <key name="level" datatype="zLOG.datatypes.logging_level" default="info"/>
+ <multisection type="loghandler" attribute="handlers" name="*"
+ required="yes"/>
+ </sectiontype>
+
+ <!-- the types that follow will be replaced by an import from the
+ ZODB package -->
<abstracttype name="storage"/>
<sectiontype name="filestorage" datatype=".filestorage"
@@ -79,7 +92,7 @@
</sectiontype>
- <sectiontype name="database" datatype=".database">
+ <sectiontype name="zodb" datatype=".database">
<multisection type="storage" name="*" attribute="storages"/>
<multikey name="mount-point" attribute="mount_points"
datatype=".mount_point"/>
@@ -192,7 +205,7 @@
<key name="zeo-client-name"
handler="zeo_client_name"/>
- <section type="logger" name="event"/>
+ <section type="eventlog" name="*" attribute="eventlog"/>
<section type="logger" name="access"/>
@@ -200,7 +213,7 @@
<multisection type="server" name="*" attribute="servers"/>
- <multisection type="database" name="*" attribute="databases"/>
+ <multisection type="zodb" name="*" attribute="databases"/>
<!-- schema ends -->
=== Removed File Zope/lib/python/Zope/Startup/logger.xml ===