[Zope3-checkins] CVS: Zope3/src/zope/app/applicationcontrol - __init__.py:1.1.2.1 applicationcontrol.py:1.1.2.1 configure.zcml:1.1.2.1 meta.zcml:1.1.2.1 metaconfigure.py:1.1.2.1 runtimeinfo.py:1.1.2.1 servercontrol.py:1.1.2.1 zopeversion.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:30:58 -0500


Update of /cvs-repository/Zope3/src/zope/app/applicationcontrol
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/applicationcontrol

Added Files:
      Tag: NameGeddon-branch
	__init__.py applicationcontrol.py configure.zcml meta.zcml 
	metaconfigure.py runtimeinfo.py servercontrol.py 
	zopeversion.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/applicationcontrol/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/applicationcontrol/applicationcontrol.py ===
##############################################################################
#
# 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: applicationcontrol.py,v 1.1.2.1 2002/12/23 19:30:56 jim Exp $"""

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()

    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.ApplicationControl.IApplicationControl.

    def getStartTime(self):
        'See Zope.App.OFS.ApplicationControl.IApplicationControl.IApplicationControl'
        return self.start_time

    #
    ############################################################

applicationController = ApplicationControl()
applicationControllerRoot = ProxyFactory(RootFolder(),
                                         NamesChecker("__class__"))


=== Added File Zope3/src/zope/app/applicationcontrol/configure.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

  <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" />

  <include package=".Views" />
  <include package=".ServerControl" />

</zopeConfigure>

<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:server-control='http://namespaces.zope.org/server-control'
>

  <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"
       />

  <include package=".Views" />

</zopeConfigure>


=== Added File Zope3/src/zope/app/applicationcontrol/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

  <include package=".ServerControl" file="meta.zcml" />
</zopeConfigure>

<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>


=== Added File Zope3/src/zope/app/applicationcontrol/metaconfigure.py ===
##############################################################################
#
# 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: metaconfigure.py,v 1.1.2.1 2002/12/23 19:30:56 jim Exp $
"""

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)



=== Added File Zope3/src/zope/app/applicationcontrol/runtimeinfo.py ===
##############################################################################
#
# 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: runtimeinfo.py,v 1.1.2.1 2002/12/23 19:30:56 jim Exp $"""

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
    
    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.ApplicationControl.IRuntimeInfo.

    def getZopeVersion(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        try:
            version_utility = getUtility(self.context, IZopeVersion)
        except ComponentLookupError:
            return ""
        return version_utility.getZopeVersion()

    def getPythonVersion(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        return sys.version

    def getPythonPath(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        return tuple(sys.path)

    def getSystemPlatform(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        if hasattr(os, "uname"):
            return os.uname()
        else:
            return (sys.platform,)

    def getCommandLine(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        return sys.argv

    def getProcessId(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        return os.getpid()
    
    def getUptime(self):
        'See Zope.App.OFS.ApplicationControl.IRuntimeInfo.IRuntimeInfo'
        return time.time() - self.context.getStartTime()

    #
    ############################################################


=== Added File Zope3/src/zope/app/applicationcontrol/servercontrol.py ===
##############################################################################
#
# 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: servercontrol.py,v 1.1.2.1 2002/12/23 19:30:56 jim Exp $"""

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.

    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.

    def shutdown(self):
        'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'
        text = ""
        order = self._shutdown_reg.keys()
        order.sort()

        for hook_ in order:
                hook = self._shutdown_reg[hook_]
                hook[0]()

    def restart(self):
        'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'

    def registerShutdownHook(self, call, priority, name):
        'See Zope.App.OFS.ApplicationControl.ServerControl.IServerControl.IServerControl'

        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.")


=== Added File Zope3/src/zope/app/applicationcontrol/zopeversion.py ===
##############################################################################
#
# 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: zopeversion.py,v 1.1.2.1 2002/12/23 19:30:56 jim Exp $"""

from zope.app.interfaces.applicationcontrol.zopeversion import IZopeVersion
import os

class ZopeVersion:

    __implements__ =  IZopeVersion

    ############################################################
    # Implementation methods for interface
    # Zope.App.OFS.ApplicationControl.IZopeVersion.

    def getZopeVersion(self):
        'See Zope.App.OFS.ApplicationControl.IZopeVersion.IZopeVersion'

        version_id = "Development/Unknown"
        version_tag = ""
        is_cvs = 0
        
        import Zope
        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()