[Zope3-checkins] CVS: Zope3/src/zope/app/applicationcontrol - __init__.py:1.2 applicationcontrol.py:1.2 configure.zcml:1.2 meta.zcml:1.2 metaconfigure.py:1.2 runtimeinfo.py:1.2 servercontrol.py:1.2 zopeversion.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:13:57 -0500
Update of /cvs-repository/Zope3/src/zope/app/applicationcontrol
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/applicationcontrol
Added Files:
__init__.py applicationcontrol.py configure.zcml meta.zcml
metaconfigure.py runtimeinfo.py servercontrol.py
zopeversion.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/applicationcontrol/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/__init__.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/applicationcontrol/applicationcontrol.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/applicationcontrol.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# 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.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.
+#
+##############################################################################
+__doc__ = """ Application Control
+
+$Id$"""
+
+from zope.app.interfaces.applicationcontrol.applicationcontrol import IApplicationControl
+from zope.app.content.folder import RootFolder
+from zope.security.checker import ProxyFactory, NamesChecker
+
+import time
+
+class ApplicationControl:
+ """ """
+
+ __implements__ = IApplicationControl
+
+ def __init__(self):
+ self.start_time = time.time()
+
+
+ def getStartTime(self):
+ return self.start_time
+
+ #
+ ############################################################
+
+applicationController = ApplicationControl()
+applicationControllerRoot = ProxyFactory(RootFolder(),
+ NamesChecker("__class__"))
=== Zope3/src/zope/app/applicationcontrol/configure.zcml 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/configure.zcml Wed Dec 25 09:12:25 2002
@@ -0,0 +1,31 @@
+<zopeConfigure xmlns="http://namespaces.zope.org/zope"
+ xmlns:server-control="http://namespaces.zope.org/server-control"
+ >
+
+ <content
+ class="zope.app.applicationcontrol.applicationcontrol.ApplicationControl">
+ <require
+ permission="zope.ManageApplication"
+ interface="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl" />
+ </content>
+
+ <adapter factory="zope.app.applicationcontrol.runtimeinfo.RuntimeInfo"
+ permission="zope.ManageApplication"
+ provides="zope.app.interfaces.applicationcontrol.runtimeinfo.IRuntimeInfo"
+ for="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl" />
+
+ <utility component="zope.app.applicationcontrol.zopeversion.ZopeVersionUtility"
+ provides="zope.app.interfaces.applicationcontrol.zopeversion.IZopeVersion" />
+
+ <utility factory="zope.app.applicationcontrol.servercontrol.ServerControl"
+ permission="zope.ManageApplication"
+ provides="zope.app.interfaces.applicationcontrol.servercontrol.IServerControl" />
+
+ <!-- Hint: Here you see how to register something on Zope shutdown -->
+ <server-control:registerShutdownHook
+ name="Shutdown logger"
+ priority="0"
+ call=".servercontrol.shutdownLogger"
+ />
+
+</zopeConfigure>
=== Zope3/src/zope/app/applicationcontrol/meta.zcml 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/meta.zcml Wed Dec 25 09:12:25 2002
@@ -0,0 +1,11 @@
+<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+
+ <directives namespace="http://namespaces.zope.org/server-control">
+ <directive name="registerShutdownHook"
+ attributes="call priority name"
+ handler="
+ zope.app.applicationcontrol.metaconfigure.registerShutdownHook"
+ />
+ </directives>
+
+</zopeConfigure>
=== Zope3/src/zope/app/applicationcontrol/metaconfigure.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/metaconfigure.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# 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.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.
+#
+##############################################################################
+""" Register ServerControl configuration directives.
+
+$Id$
+"""
+
+from zope.component import getUtility
+from zope.app.interfaces.applicationcontrol.servercontrol import IServerControl
+from zope.configuration.action import Action
+
+
+def registerShutdownHook(_context, call, name, priority):
+ """Register a shutdown hook with the current server control utility"""
+ return [
+ Action(
+ discriminator = ('server-control:registerShutdownHook', name),
+ callable = doRegisterShutdownHook,
+ args = (_context, call, priority, name),
+ )
+ ]
+
+def doRegisterShutdownHook(_context, call, priority, name):
+ server_control = getUtility(_context, IServerControl)
+ server_control.registerShutdownHook(_context.resolve(call), priority, name)
=== Zope3/src/zope/app/applicationcontrol/runtimeinfo.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/runtimeinfo.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# 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.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.
+#
+##############################################################################
+__doc__ = """ Runtime Information
+
+$Id$"""
+
+from zope.app.interfaces.applicationcontrol.runtimeinfo import IRuntimeInfo
+from zope.app.interfaces.applicationcontrol.applicationcontrol import IApplicationControl
+from zope.component import getUtility, ComponentLookupError
+from zope.app.interfaces.applicationcontrol.zopeversion import IZopeVersion
+import sys, os, time
+
+class RuntimeInfo:
+
+ __implements__ = IRuntimeInfo
+ __used_for__ = IApplicationControl
+
+ def __init__(self, context):
+ self.context = context
+
+ def getZopeVersion(self):
+ try:
+ version_utility = getUtility(self.context, IZopeVersion)
+ except ComponentLookupError:
+ return ""
+ return version_utility.getZopeVersion()
+
+ def getPythonVersion(self):
+ return sys.version
+
+ def getPythonPath(self):
+ return tuple(map(str, sys.path))
+
+ def getSystemPlatform(self):
+ if hasattr(os, "uname"):
+ return os.uname()
+ else:
+ return (sys.platform,)
+
+ def getCommandLine(self):
+ return sys.argv
+
+ def getProcessId(self):
+ return os.getpid()
+
+ def getUptime(self):
+ return time.time() - self.context.getStartTime()
+
+ #
+ ############################################################
=== Zope3/src/zope/app/applicationcontrol/servercontrol.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/applicationcontrol/servercontrol.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# 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.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.
+#
+##############################################################################
+__doc__ = """ Server Control Implementation
+
+$Id$"""
+
+from zope.app.interfaces.applicationcontrol.servercontrol import \
+ IServerControl, ServerControlError, DoublePriorityError, NotCallableError
+import logging
+
+import sys
+
+
+class ServerControl:
+
+ __implements__ = IServerControl
+
+ def __init__(self):
+ self._shutdown_reg = {} # This is the actual shutdown registry.
+ # It will hold the hooks accessible by their
+ # priority. The priority actually needs to be
+ # a floating point value, to allow most fine
+ # grained control on the priority.
+
+
+ def shutdown(self):
+ text = ""
+ order = self._shutdown_reg.keys()
+ order.sort()
+
+ for hook_ in order:
+ hook = self._shutdown_reg[hook_]
+ hook[0]()
+
+ def restart(self):
+ 'XXX'
+
+ def registerShutdownHook(self, call, priority, name):
+ priority = float(priority)
+ if priority in self._shutdown_reg:
+ raise DoublePriorityError, (call, priority, name)
+
+ if not callable(call):
+ raise NotCallableError, (call, priority, name)
+
+ self._shutdown_reg.update({priority: (call, name)})
+
+
+ #
+ ############################################################
+
+
+
+## simple log notification for shutdown
+def shutdownLogger():
+ """simple shutdown logger"""
+ logging.warn("ServerControl: Server is going to be shut down.")
=== Zope3/src/zope/app/applicationcontrol/zopeversion.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:13:57 2002
+++ Zope3/src/zope/app/applicationcontrol/zopeversion.py Wed Dec 25 09:12:25 2002
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# 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.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.
+#
+##############################################################################
+__doc__ = """Zope version
+
+$Id$"""
+
+import os
+
+import zope
+
+from zope.app.interfaces.applicationcontrol.zopeversion import IZopeVersion
+
+
+class ZopeVersion:
+
+ __implements__ = IZopeVersion
+
+ def getZopeVersion(self):
+
+ version_id = "Development/Unknown"
+ version_tag = ""
+ is_cvs = 0
+
+ zopedir = os.path.dirname(zope.__file__)
+
+ # is this a CVS checkout?
+ cvsdir = os.path.join(zopedir, "CVS" )
+ if os.path.isdir(cvsdir):
+ is_cvs = 1
+ tagfile = os.path.join(cvsdir, "Tag")
+
+ # get the tag information
+ if os.path.isfile(tagfile):
+ f = open(tagfile)
+ tag = f.read()
+ if tag.startswith("T"):
+ version_tag = " (%s)" % tag[1:-1]
+
+ # try to get official Zope release information
+ versionfile = os.path.join(zopedir, "version.txt")
+ if os.path.isfile(versionfile) and not is_cvs:
+ f = open(versionfile)
+ version_id = f.read().split("\n")[0] or version_id
+
+ version = "%s%s" % (version_id, version_tag)
+ return version
+
+ZopeVersionUtility = ZopeVersion()