diff --git a/applicationcontrol.py b/applicationcontrol.py new file mode 100644 index 0000000..789d031 --- /dev/null +++ b/applicationcontrol.py @@ -0,0 +1,47 @@ +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +"""Application Control + +$Id$""" +__docformat__ = 'restructuredtext' + +from zope.app.applicationcontrol.interfaces import IApplicationControl +from zope.app.location import Location +from zope.security.checker import ProxyFactory, NamesChecker +import time +import zope.interface +import zope.app.traversing.interfaces + +class ApplicationControl(Location): + + zope.interface.implements(IApplicationControl) + + def __init__(self): + self.start_time = time.time() + + def getStartTime(self): + return self.start_time + + +applicationControllerRoot = Location() +zope.interface.directlyProvides( + applicationControllerRoot, + zope.app.traversing.interfaces.IContainmentRoot, + ) +applicationControllerRoot = ProxyFactory(applicationControllerRoot, + NamesChecker("__class__")) + +applicationController = ApplicationControl() +applicationController.__parent__ = applicationControllerRoot +applicationController.__name__ = '++etc++process' diff --git a/browser/runtimeinfo.py b/browser/runtimeinfo.py index d5ba0dc..78d240f 100644 --- a/browser/runtimeinfo.py +++ b/browser/runtimeinfo.py @@ -15,6 +15,8 @@ $Id$ """ +__docformat__ = 'restructuredtext' + from zope.app.applicationcontrol.interfaces import IRuntimeInfo from zope.app.i18n import ZopeMessageIDFactory as _ diff --git a/browser/servercontrol.py b/browser/servercontrol.py index 72c6ad9..a78ed86 100644 --- a/browser/servercontrol.py +++ b/browser/servercontrol.py @@ -15,6 +15,8 @@ $Id$ """ +__docformat__ = 'restructuredtext' + from zope.app import zapi from zope.app.applicationcontrol.interfaces import IServerControl diff --git a/browser/translationdomaincontrol.py b/browser/translationdomaincontrol.py index fc595f8..e875abb 100644 --- a/browser/translationdomaincontrol.py +++ b/browser/translationdomaincontrol.py @@ -15,6 +15,8 @@ $Id$ """ +__docformat__ = 'restructuredtext' + from zope.i18n.interfaces import ITranslationDomain from zope.app import zapi from zope.app.i18n import ZopeMessageIDFactory as _ diff --git a/browser/zodbcontrol.py b/browser/zodbcontrol.py index 8dc3b3f..b728e17 100644 --- a/browser/zodbcontrol.py +++ b/browser/zodbcontrol.py @@ -15,6 +15,8 @@ $Id$ """ +__docformat__ = 'restructuredtext' + from ZODB.FileStorage.FileStorage import FileStorageError from zope.app.i18n import ZopeMessageIDFactory as _ diff --git a/interfaces.py b/interfaces.py new file mode 100644 index 0000000..61a2fd1 --- /dev/null +++ b/interfaces.py @@ -0,0 +1,105 @@ +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +"""Application Control Interface + +$Id$ +""" +__docformat__ = 'restructuredtext' + +from zope.interface import Interface + +class IApplicationControl(Interface): + """The application control instance is usually generated upon startup and + can therefore record the startup time.""" + + def getStartTime(): + """Return time the application started in seconds since the epoch.""" + + +class IRuntimeInfo(Interface): + """Runtime Information Adapter for Application Control""" + + def getPreferredEncoding(): + """Return the encoding used for text data, according + to user system preferences""" + + def getFileSystemEncoding(): + """Return the name of the encoding used to convert + Unicode filenames into system file names""" + + def getZopeVersion(): + """Return a string containing the descriptive version of the + current zope installation""" + + def getPythonVersion(): + """Return an unicode string containing verbose description + of the python interpreter""" + + def getPythonPath(): + """Return a tuple containing an unicode strings containing + the lookup paths of the python interpreter""" + + def getSystemPlatform(): + """Return an unicode string containing the system platform name + """ + + def getCommandLine(): + """Return the command line string Zope was invoked with""" + + def getProcessId(): + """Return the process id number currently serving the request""" + + def getUptime(): + """Return the Zope server uptime in seconds""" + + +class IZopeVersion(Interface): + """ Zope version """ + + def getZopeVersion(): + """Return a string containing the Zope version (possibly including + CVS information)""" + + +class IServerControl(Interface): + """Defines methods for shutting down and restarting the server. + + This utility also keeps a registry of things to call when shutting down + zope. You can register using this interface or the zcml on the global + ServerController instance. + """ + + def shutdown(time=0): + """Shutdown the server. + + The `time` should be greater-equal 0. + + If the `time` is 0, the we do a hard shutdown, i.e. closing all sockets + without waiting for tasks to complete. + + If the `time` is not 0, then we will give the tasks `time` seconds to + finish before shutting down. + """ + + def restart(time=0): + """Restart the server. + + The `time` should be greater-equal 0. + + If the `time` is 0, the we do a hard shutdown, i.e. closing all sockets + without waiting for tasks to complete. + + If the `time` is not 0, then we will give the tasks `time` seconds to + finish before shutting down. + """ diff --git a/runtimeinfo.py b/runtimeinfo.py new file mode 100644 index 0000000..289fe46 --- /dev/null +++ b/runtimeinfo.py @@ -0,0 +1,91 @@ +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (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. +# +############################################################################## +""" Runtime Information + +$Id$ +""" +__docformat__ = 'restructuredtext' + +import sys, os, time + +try: + import locale +except ImportError: + locale = None + +from zope.app.applicationcontrol.interfaces import \ + IRuntimeInfo, IApplicationControl, IZopeVersion +from zope.component import getUtility, ComponentLookupError +from zope.interface import implements + +class RuntimeInfo(object): + implements(IRuntimeInfo) + __used_for__ = IApplicationControl + + def __init__(self, context): + self.context = context + + def getPreferredEncoding(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + if locale is not None: + try: + return locale.getpreferredencoding() + except locale.Error: + pass + return sys.getdefaultencoding() + + def getFileSystemEncoding(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + enc = sys.getfilesystemencoding() + if enc is None: + enc = self.getPreferredEncoding() + return enc + + def getZopeVersion(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + try: + version_utility = getUtility(IZopeVersion) + except ComponentLookupError: + return "" + return version_utility.getZopeVersion() + + def getPythonVersion(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + return unicode(sys.version, self.getPreferredEncoding()) + + def getPythonPath(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + enc = self.getFileSystemEncoding() + return tuple([unicode(path, enc) for path in sys.path]) + + def getSystemPlatform(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + # FIXME: platform.platform()? + if hasattr(os, "uname"): + info = os.uname() + else: + info = (sys.platform,) + return unicode(" ".join(info), self.getPreferredEncoding()) + + def getCommandLine(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + return " ".join(sys.argv) + + def getProcessId(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + return os.getpid() + + def getUptime(self): + """See zope.app.applicationcontrol.interfaces.IRuntimeInfo""" + return time.time() - self.context.getStartTime() diff --git a/zopeversion.py b/zopeversion.py index 89c4ee3..3bac42d 100644 --- a/zopeversion.py +++ b/zopeversion.py @@ -15,6 +15,8 @@ $Id$ """ +__docformat__ = 'restructuredtext' + import os import re