[Zope3-checkins] CVS: Zope3/src/zope/app/browser/applicationcontrol - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 runtimeinfo.pt:1.1.2.1 runtimeinfo.py:1.1.2.1 server-control.pt:1.1.2.1 servercontrol.py:1.1.2.1

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


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

Added Files:
      Tag: NameGeddon-branch
	__init__.py configure.zcml runtimeinfo.pt runtimeinfo.py 
	server-control.pt servercontrol.py 
Log Message:
Initial renaming before debugging

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


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

  <!-- ServerControl View Directives -->
  <browser:view
      for="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl"
      permission="Zope.ManageApplication"
      factory="zope.app.browser.applicationcontrol.servercontrol.ServerControlView">
    
    <browser:page name="ServerControlForm.html" attribute="index" />
    <browser:page name="ServerControl.html"     attribute="action" />
  </browser:view>
 

  <browser:menuItem
      for="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl"
      menu="zmi_views"
      action="ServerControlForm.html"
      title="Server control" 
      />



</zopeConfigure>

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

  <browser:view 
      for="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl"
      factory="zope.app.browser.applicationcontrol.runtimeinfo.RuntimeInfoView" 
      permission="Zope.ManageApplication" >

    <browser:page name="index.html" attribute="index" />
  </browser:view> 

  <browser:menuItem
      for="zope.app.interfaces.applicationcontrol.applicationcontrol.IApplicationControl"
      menu="zmi_views"
      action="index.html"
      title="Runtime Information"
      />

</zopeConfigure>


=== Added File Zope3/src/zope/app/browser/applicationcontrol/runtimeinfo.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<title>Zope Runtime Information</title>
</head>
<body>
<div metal:fill-slot="body">

<ul tal:define="runtime_info view/runtimeInfo">
   <li>Zope version: <span tal:replace="runtime_info/ZopeVersion" />
   <li>Python version: <span tal:replace="runtime_info/PythonVersion" />
   <li>System platform: <span tal:replace="runtime_info/SystemPlatform" />
   <li>Command line: <span tal:replace="runtime_info/CommandLine" />
   <li>Process id: <span tal:replace="runtime_info/ProcessId" />
   <li>Uptime: <span tal:replace="runtime_info/Uptime" />
   <li>Python path:</li>
      <ul>
        <li tal:repeat="path runtime_info/PythonPath" tal:content="path">path</li>
      </ul>
   <!-- # XXX UI folks: following line want's special attention. The hardcoding should
          be removed someday. -->
   <li tal:condition="runtime_info/Hint | nothing" style="color:red;"
       tal:content="runtime_info/Hint" />
</ul>

</div>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/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.
# 
##############################################################################
"""Define runtime information view component for Application Control

$Id: runtimeinfo.py,v 1.1.2.1 2002/12/23 19:30:59 jim Exp $
"""

from zope.publisher.browser import BrowserView
from zope.app.interfaces.applicationcontrol.runtimeinfo import IRuntimeInfo
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.component import getAdapter
from zope.component import ComponentLookupError

class RuntimeInfoView(BrowserView):
    
    def runtimeInfo(self):
        formatted = {}  # will contain formatted runtime information
        
        try:
            runtime_info = getAdapter(self.context, IRuntimeInfo)
        except ComponentLookupError:
            # XXX We avoid having errors in the ApplicationController,
            # because all those things need to stay accessible.
            # Everybody ok with that?
            formatted['ZopeVersion'] = "N/A"
            formatted['PythonVersion'] = "N/A"
            formatted['PythonPath'] = "N/A"
            formatted['SystemPlatform'] = "N/A"
            formatted['CommandLine'] = "N/A"
            formatted['ProcessId'] = "N/A"
            formatted['Hint'] = "Could not retrieve runtime information."
        
        formatted['ZopeVersion'] = runtime_info.getZopeVersion()
        formatted['PythonVersion'] = runtime_info.getPythonVersion()
        formatted['PythonPath'] = runtime_info.getPythonPath()
        formatted['SystemPlatform'] = " ".join(runtime_info.getSystemPlatform())
        formatted['CommandLine'] = " ".join(runtime_info.getCommandLine())
        formatted['ProcessId'] = runtime_info.getProcessId()

        # make a unix "uptime" uptime format
        uptime = runtime_info.getUptime()
        days = int(uptime / (60*60*24))
        uptime = uptime - days * (60*60*24)
        
        hours = int(uptime / (60*60))
        uptime = uptime - hours * (60*60)

        minutes = int(uptime / 60)
        uptime = uptime - minutes * 60

        seconds = uptime
        formatted['Uptime'] = "%s%02d:%02d:%02d" % (
            ((days or "") and "%d days, " % days), hours, minutes, seconds)

        return formatted
        
    index = ViewPageTemplateFile('runtimeinfo.pt')


=== Added File Zope3/src/zope/app/browser/applicationcontrol/server-control.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<title>Zope Stub Server Controller</title>
</head>
<body>
<div metal:fill-slot="body">

 <form name="servercontrol" action="ServerControl.html" method="post">
  <input type="submit" name="restart" value="Restart server" /> <br />
  <input type="submit" name="shutdown" value="Shutdown server" /> <br />
 </form>
 
</div>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/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 View

$Id: servercontrol.py,v 1.1.2.1 2002/12/23 19:30:59 jim Exp $ """

from zope.publisher.browser import BrowserView
from Zope.App.PageTemplate import ViewPageTemplateFile
from zope.app.interfaces.applicationcontrol.servercontrol \
     import IServerControl
from zope.component import getUtility

class ServerControlView(BrowserView):
    
    def serverControl(self):
        # XXX Refactor alarm! This is *required*. We really
        # rely on it beeing there. If it was a utility,
        # we wouldn't care, if the ServerControl is gone,
        # but actually we do. Maybe this should be a service ...
        return getUtility(self.context, IServerControl)
    
    def action(self):
        """Do the shutdown/restart!"""
        if 'restart' in self.request:
            return self.serverControl().restart() or "You restarted the server."
        elif 'shutdown' in self.request:
            return self.serverControl().shutdown() or \
            "You shut down the server."

    index = ViewPageTemplateFile('server-control.pt')