Commit aef46932 authored by Chris McDonough's avatar Chris McDonough

Do a bit of cleanup in __init__ (add explanatory comments, move side-effect...

Do a bit of cleanup in __init__ (add explanatory comments, move side-effect functions to a utility module).
parent 823a2ed7
......@@ -12,59 +12,25 @@
##############################################################################
import sys
import utils
from medusa.test import max_sockets
CONNECTION_LIMIT=max_sockets.max_select_sockets()
ZSERVER_VERSION='1.1'
try:
import App.version_txt
ZOPE_VERSION=App.version_txt.version_txt()
except:
ZOPE_VERSION='experimental'
#########################################################
### declarations used by external packages
# the exit code used to exit a Zope process cleanly
exit_code = 0
# Try to poke zLOG default logging into asyncore
# XXX We should probably should do a better job of this,
# however that would mean that ZServer required zLOG.
# (Is that really a bad thing?)
try:
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
except ImportError:
pass
else:
register_subsystem('ZServer')
severity={'info':INFO, 'warning':WARNING, 'error': ERROR}
def log_info(self, message, type='info'):
if message[:14]=='adding channel' or \
message[:15]=='closing channel' or \
message == 'Computing default hostname':
LOG('ZServer', BLATHER, message)
else:
LOG('ZServer', severity[type], message)
import asyncore
asyncore.dispatcher.log_info=log_info
# A routine to try to arrange for request sockets to be closed
# on exec. This makes it easier for folks who spawn long running
# processes from Zope code. Thanks to Dieter Maurer for this.
try:
import fcntl
def requestCloseOnExec(sock):
try:
fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
except: # XXX What was this supposed to catch?
pass
# the ZServer version number
ZSERVER_VERSION='1.1'
except (ImportError, AttributeError):
# the maximum number of incoming connections to ZServer
CONNECTION_LIMIT=utils.getMaxSockets()
def requestCloseOnExec(sock):
pass
# the Zope version string
ZOPE_VERSION=utils.getZopeVersion()
# backwards compatibility aliases
from utils import requestCloseOnExec
import asyncore
from medusa import resolver, logger
from HTTPServer import zhttp_server, zhttp_handler
......@@ -74,5 +40,14 @@ from FTPServer import FTPServer
from PubCore import setNumberOfThreads
from medusa.monitor import secure_monitor_server
# override the service name in logger.syslog_logger
logger.syslog_logger.svc_name='ZServer'
### end declarations
##########################################################
# we need to patch asyncore's dispatcher class with a new
# log_info method so we see medusa messages in the zLOG log
utils.patchAsyncoreLogger()
# we need to patch the 'service name' of the medusa syslog logger
utils.patchSyslogServiceName()
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
""" A set of utility routines used by asyncore initialization """
def getMaxSockets():
from medusa.test import max_sockets
return max_sockets.max_select_sockets()
def getZopeVersion():
import App.version_txt
App.version_txt.version_txt()
def patchAsyncoreLogger():
# Poke zLOG default logging into asyncore to send
# messages to zLOG instead of medusa logger
from zLOG import LOG, register_subsystem, BLATHER, INFO, WARNING, ERROR
register_subsystem('ZServer')
severity={'info':INFO, 'warning':WARNING, 'error': ERROR}
def log_info(self, message, type='info'):
if message[:14]=='adding channel' or \
message[:15]=='closing channel' or \
message == 'Computing default hostname':
LOG('ZServer', BLATHER, message)
else:
LOG('ZServer', severity[type], message)
import asyncore
asyncore.dispatcher.log_info=log_info
# A routine to try to arrange for request sockets to be closed
# on exec. This makes it easier for folks who spawn long running
# processes from Zope code. Thanks to Dieter Maurer for this.
try:
import fcntl
def requestCloseOnExec(sock):
try:
fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
except: # XXX What was this supposed to catch?
pass
except (ImportError, AttributeError):
def requestCloseOnExec(sock):
pass
def patchSyslogServiceName():
from medusa import logger
# override the service name in logger.syslog_logger
logger.syslog_logger.svc_name='ZServer'
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