-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Phil Ruggera
committed
Sep 2, 2004
1 parent
bbdd86a
commit 6a3505a
Showing
8 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
$Id$ | ||
""" | ||
__docformat__ = 'restructuredtext' | ||
|
||
import os | ||
import re | ||
|
||
|