[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/applicationcontrol/
Runtime info code cleanup
Dmitry Vasiliev
dima at hlabs.spb.ru
Sat Apr 2 14:16:10 EST 2005
Log message for revision 29842:
Runtime info code cleanup
Changed:
U Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.pt
U Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.py
U Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_runtimeinfoview.py
U Zope3/trunk/src/zope/app/applicationcontrol/runtimeinfo.py
U Zope3/trunk/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py
-=-
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.pt
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.pt 2005-04-02 19:05:45 UTC (rev 29841)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.pt 2005-04-02 19:16:09 UTC (rev 29842)
@@ -6,53 +6,58 @@
<body>
<div metal:fill-slot="body">
- <ul tal:define="runtime_info view/runtimeInfo">
- <li>
- <span i18n:translate="">Zope version</span>:
- <span tal:replace="runtime_info/ZopeVersion" />
- </li>
- <li>
- <span i18n:translate="">Python version</span>:
- <span tal:replace="runtime_info/PythonVersion" />
- </li>
- <li>
- <span i18n:translate="">System platform</span>:
- <span tal:replace="runtime_info/SystemPlatform" />
- </li>
- <li>
- <span i18n:translate="">Preferred encoding</span>:
- <span tal:replace="runtime_info/PreferredEncoding" />
- </li>
- <li>
- <span i18n:translate="">FileSytem encoding</span>:
- <span tal:replace="runtime_info/FileSystemEncoding" />
- </li>
- <li>
- <span i18n:translate="">Command line</span>:
- <span tal:replace="runtime_info/CommandLine" />
- </li>
- <li>
- <span i18n:translate="">Process id</span>:
- <span tal:replace="runtime_info/ProcessId" />
- </li>
- <li>
- <span i18n:translate="">Uptime</span>:
- <span tal:replace="runtime_info/Uptime" />
- </li>
- <li>
- <span i18n:translate="">Python path</span>:
- <ul>
+ <tal:block tal:define="runtime_info view/runtimeInfo">
+ <div class="row">
+ <div class="label" i18n:translate="">Uptime</div>
+ <div class="field"
+ tal:content="runtime_info/Uptime">Time</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">System platform</div>
+ <div class="field"
+ tal:content="runtime_info/SystemPlatform">Platform</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Zope version</div>
+ <div class="field"
+ tal:content="runtime_info/ZopeVersion">Version</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Python version</div>
+ <div class="field"
+ tal:content="runtime_info/PythonVersion">Version</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Command line</div>
+ <div class="field"
+ tal:content="runtime_info/CommandLine">Command line</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Preferred encoding</div>
+ <div class="field"
+ tal:content="runtime_info/PreferredEncoding">Encoding</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">FileSytem encoding</div>
+ <div class="field"
+ tal:content="runtime_info/FileSystemEncoding">Encoding</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Process id</div>
+ <div class="field"
+ tal:content="runtime_info/ProcessId">ID</div>
+ </div>
+ <div class="row">
+ <div class="label" i18n:translate="">Python path</div>
+ <div class="field">
+ <ul>
<li tal:repeat="path runtime_info/PythonPath"
tal:content="path">path</li>
- </ul>
- </li>
+ </ul>
+ </div>
+ </div>
+ </tal:block>
- <!-- # XXX UI folks: following line wants special attention. The
- hardcoding should be removed someday. -->
- <li tal:condition="runtime_info/Hint | nothing" style="color:red;"
- tal:content="runtime_info/Hint" i18n:translate="" />
- </ul>
-
</div>
</body>
</html>
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.py 2005-04-02 19:05:45 UTC (rev 29841)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/runtimeinfo.py 2005-04-02 19:16:09 UTC (rev 29842)
@@ -21,51 +21,52 @@
from zope.app.i18n import ZopeMessageIDFactory as _
+
class RuntimeInfoView(object):
+ _fields = (
+ "ZopeVersion",
+ "PythonVersion",
+ "PythonPath",
+ "SystemPlatform",
+ "PreferredEncoding",
+ "FileSystemEncoding",
+ "CommandLine",
+ "ProcessId"
+ )
+ _unavailable = _("Unavailable")
+
def runtimeInfo(self):
- formatted = {} # will contain formatted runtime information
-
try:
- runtime_info = IRuntimeInfo(self.context)
- formatted['ZopeVersion'] = runtime_info.getZopeVersion()
- formatted['PythonVersion'] = runtime_info.getPythonVersion()
- formatted['PythonPath'] = runtime_info.getPythonPath()
- formatted['SystemPlatform'] = runtime_info.getSystemPlatform()
- formatted['PreferredEncoding'] = runtime_info.getPreferredEncoding()
- formatted['FileSystemEncoding'] = \
- runtime_info.getFileSystemEncoding()
- formatted['CommandLine'] = runtime_info.getCommandLine()
- formatted['ProcessId'] = runtime_info.getProcessId()
+ ri = IRuntimeInfo(self.context)
+ except TypeError:
+ formatted = dict.fromkeys(self._fields, self._unavailable)
+ formatted["Uptime"] = self._unavailable
+ else:
+ formatted = self._getInfo(ri)
+ return formatted
- # make a unix "uptime" uptime format
- uptime = long(runtime_info.getUptime())
- minutes, seconds = divmod(uptime, 60)
- hours, minutes = divmod(minutes, 60)
- days, hours = divmod(hours, 24)
+ def _getInfo(self, ri):
+ formatted = {}
+ for name in self._fields:
+ try:
+ value = getattr(ri, "get" + name)()
+ except ValueError:
+ value = self._unavailable
+ formatted[name] = value
+ formatted["Uptime"] = self._getUptime(ri)
+ return formatted
- uptime = _('${days} day(s) ${hours}:${minutes}:${seconds}')
- uptime.mapping = {'days': '%d' %days,
- 'hours': '%02d' %hours,
- 'minutes': '%02d' %minutes,
- 'seconds': '%02d' %seconds}
+ def _getUptime(self, ri):
+ # make a unix "uptime" uptime format
+ uptime = long(ri.getUptime())
+ minutes, seconds = divmod(uptime, 60)
+ hours, minutes = divmod(minutes, 60)
+ days, hours = divmod(hours, 24)
- formatted['Uptime'] = uptime
-
- except (TypeError, UnicodeError):
- # We avoid having errors in the ApplicationController,
- # because all those things need to stay accessible.
- na = _("n/a")
- formatted['ZopeVersion'] = na
- formatted['PythonVersion'] = na
- formatted['PythonPath'] = (na,)
- formatted['SystemPlatform'] = na
- formatted['PreferredEncoding'] = na
- formatted['FileSystemEncoding'] = na
- formatted['CommandLine'] = na
- formatted['ProcessId'] = na
- formatted['Uptime'] = na
- formatted['Hint'] = _("Could not retrieve runtime information.")
-
- return formatted
-
+ uptime = _('${days} day(s) ${hours}:${minutes}:${seconds}')
+ uptime.mapping = {'days': '%d' % days,
+ 'hours': '%02d' % hours,
+ 'minutes': '%02d' % minutes,
+ 'seconds': '%02d' % seconds}
+ return uptime
Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_runtimeinfoview.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_runtimeinfoview.py 2005-04-02 19:05:45 UTC (rev 29841)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/tests/test_runtimeinfoview.py 2005-04-02 19:16:09 UTC (rev 29842)
@@ -48,9 +48,9 @@
assert_keys.sort()
test_keys.sort()
- self.failUnless(assert_keys == test_keys)
+ self.failUnlessEqual(assert_keys, test_keys)
- self.failUnless(test_format["ZopeVersion"] != "n/a")
+ self.failUnlessEqual("Unavailable", test_format["ZopeVersion"])
def test_RuntimeInfoFailureView(self):
test_runtimeinfoview = self._TestView__newView(applicationController)
@@ -60,14 +60,15 @@
assert_keys = ['ZopeVersion', 'PythonVersion', 'PythonPath',
'SystemPlatform', 'PreferredEncoding', 'FileSystemEncoding',
- 'CommandLine', 'ProcessId', 'Uptime', 'Hint']
+ 'CommandLine', 'ProcessId', 'Uptime']
test_keys = test_format.keys()
assert_keys.sort()
test_keys.sort()
- self.failUnless(assert_keys == test_keys)
+ self.failUnlessEqual(assert_keys, test_keys)
- self.failUnless(test_format["ZopeVersion"] == "n/a")
+ for key in assert_keys:
+ self.failUnlessEqual("Unavailable", test_format[key])
def test_suite():
Modified: Zope3/trunk/src/zope/app/applicationcontrol/runtimeinfo.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/runtimeinfo.py 2005-04-02 19:05:45 UTC (rev 29841)
+++ Zope3/trunk/src/zope/app/applicationcontrol/runtimeinfo.py 2005-04-02 19:16:09 UTC (rev 29842)
@@ -17,24 +17,30 @@
"""
__docformat__ = 'restructuredtext'
-import sys, os, time
+import sys
+import os
+import time
try:
import locale
except ImportError:
locale = None
-try:
- import platform
-except ImportError:
- platform = None
+import platform
-from zope.app.applicationcontrol.interfaces import \
- IRuntimeInfo, IApplicationControl, IZopeVersion
from zope.component import getUtility, ComponentLookupError
from zope.interface import implements
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+from zope.app.applicationcontrol.interfaces import IRuntimeInfo
+from zope.app.applicationcontrol.interfaces import IApplicationControl
+from zope.app.applicationcontrol.interfaces import IZopeVersion
+
+
class RuntimeInfo(object):
+ """Runtime information."""
+
implements(IRuntimeInfo)
__used_for__ = IApplicationControl
@@ -62,7 +68,7 @@
try:
version_utility = getUtility(IZopeVersion)
except ComponentLookupError:
- return ""
+ return _("Unavailable")
return version_utility.getZopeVersion()
def getPythonVersion(self):
@@ -76,21 +82,23 @@
def getSystemPlatform(self):
"""See zope.app.applicationcontrol.interfaces.IRuntimeInfo"""
- if platform is not None:
- info = " ".join(platform.uname())
- elif hasattr(os, "uname"):
- info = " ".join(os.uname())
+ info = []
+ enc = self.getPreferredEncoding()
+ for i in platform.uname():
+ try:
+ t = unicode(i, enc)
+ except ValueError:
+ continue
+ info.append(t)
+ if info:
+ info = u" ".join(info)
else:
- info = sys.platform
- try:
- return unicode(info, self.getPreferredEncoding())
- except ValueError:
- pass
- return unicode(info, "latin1")
+ info = unicode(sys.platform, enc)
+ return info
def getCommandLine(self):
"""See zope.app.applicationcontrol.interfaces.IRuntimeInfo"""
- return " ".join(sys.argv)
+ return unicode(" ".join(sys.argv), self.getPreferredEncoding())
def getProcessId(self):
"""See zope.app.applicationcontrol.interfaces.IRuntimeInfo"""
Modified: Zope3/trunk/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py 2005-04-02 19:05:45 UTC (rev 29841)
+++ Zope3/trunk/src/zope/app/applicationcontrol/tests/test_runtimeinfo.py 2005-04-02 19:16:09 UTC (rev 29842)
@@ -78,7 +78,7 @@
runtime_info = self._Test__new()
# we expect that there is no utility
- self.assertEqual(runtime_info.getZopeVersion(), "")
+ self.assertEqual(runtime_info.getZopeVersion(), u"Unavailable")
zapi.getSiteManager().provideUtility(IZopeVersion, TestZopeVersion())
self.assertEqual(runtime_info.getZopeVersion(),
More information about the Zope3-Checkins
mailing list