Skip to content

Commit

Permalink
- Add a Configuration details tab to the Control_Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 4, 2019
1 parent bcd101c commit 42a2b06
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 35 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Fixes
Features
++++++++

- Add a Configuration details tab to the Control_Panel

- Resurrect the Interfaces ZMI tab
(`#450 <https://github.com/zopefoundation/Zope/issues/450>`_)

Expand Down
70 changes: 69 additions & 1 deletion src/App/ApplicationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import os
import sys
import time

from six.moves.urllib import parse

Expand Down Expand Up @@ -49,10 +50,14 @@ class DatabaseChooser(Tabs, Traversable, Implicit):
name = title = 'Database Management'
meta_type = 'Database Management'

manage_main = PageTemplateFile('www/chooseDatabase.pt', globals())
manage_main = manage_workspace = PageTemplateFile('www/chooseDatabase.pt',
globals())
manage_main.__name__ = 'manage_main'
manage_main._need__name__ = 0
manage_options = (
{'label': 'Control Panel', 'action': '../manage_main'},
{'label': 'Databases', 'action': 'manage_main'},
{'label': 'Configuration', 'action': '../Configuration/manage_main'},
)
MANAGE_TABS_NO_BANNER = True

Expand Down Expand Up @@ -82,6 +87,50 @@ def __bobo_traverse__(self, request, name):
InitializeClass(DatabaseChooser)


class ConfigurationViewer(Tabs, Traversable, Implicit):
""" Provides information about the running configuration
"""
manage = manage_main = manage_workspace = DTMLFile('dtml/cpConfiguration',
globals())
manage_main._setName('manage_main')
id = 'Configuration'
name = title = 'Configuration Viewer'
meta_type = name
zmi_icon = 'fa fa-cog'
manage_options = (
{'label': 'Control Panel', 'action': '../manage_main'},
{'label': 'Databases', 'action': '../Database/manage_main'},
{'label': 'Configuration', 'action': 'manage_main'},
)
MANAGE_TABS_NO_BANNER = True

def manage_getSysPath(self):
return sorted(sys.path)

def manage_getConfiguration(self):
config_results = []
config = getConfiguration()

try:
keys = config.getSectionAttributes()
except AttributeError:
# This happens in unit tests with a DefaultConfiguration object
keys = config.__dict__.keys()

for key in keys:

# Databases are visible on the Database Chooser already
if key == 'databases':
continue

config_results.append({'name': key,
'value': str(getattr(config, key))})
return config_results


InitializeClass(ConfigurationViewer)


class ApplicationManager(Persistent, Tabs, Traversable, Implicit):
"""System management
"""
Expand All @@ -92,14 +141,17 @@ class ApplicationManager(Persistent, Tabs, Traversable, Implicit):
name = title = 'Control Panel'
meta_type = 'Control Panel'
zmi_icon = 'fa fa-cog'
process_start = int(time.time())

Database = DatabaseChooser()
Configuration = ConfigurationViewer()

manage = manage_main = DTMLFile('dtml/cpContents', globals())
manage_main._setName('manage_main')
manage_options = (
{'label': 'Control Panel', 'action': 'manage_main'},
{'label': 'Databases', 'action': 'Database/manage_main'},
{'label': 'Configuration', 'action': 'Configuration/manage_main'},
)
MANAGE_TABS_NO_BANNER = True

Expand All @@ -112,6 +164,22 @@ def version_txt(self):
def process_id(self):
return os.getpid()

def process_time(self, _when=None):
if _when is None:
_when = time.time()
s = int(_when) - self.process_start
d = int(s / 86400)
s = s - (d * 86400)
h = int(s / 3600)
s = s - (h * 3600)
m = int(s / 60)
s = s - (m * 60)
d = d and ('%d day%s' % (d, (d != 1 and 's' or ''))) or ''
h = h and ('%d hour%s' % (h, (h != 1 and 's' or ''))) or ''
m = m and ('%d min' % m) or ''
s = '%d sec' % s
return '%s %s %s %s' % (d, h, m, s)

def sys_version(self):
return sys.version

Expand Down
32 changes: 32 additions & 0 deletions src/App/dtml/cpConfiguration.dtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<dtml-var manage_page_header>

<dtml-with "_(management_view='Configuration')">
<dtml-var manage_tabs>
</dtml-with>

<main class="container-fluid">

<p class="form-help mt-4">
Configuration information for the running Zope process.
</p>

<table class="table">
<dtml-in manage_getConfiguration mapping sort="name">
<tr>
<th class="text-muted">&dtml-name;</th>
<td class="code syspath">&dtml-value;</td>
</tr>
</dtml-in>
<tr>
<th class="text-muted">Python path (sys.path)</th>
<td class="code syspath">
<dtml-in manage_getSysPath>
<dtml-var sequence-item><br/>
</dtml-in>
</td>
</tr>
</table>

</main>

<dtml-var manage_page_footer>
70 changes: 37 additions & 33 deletions src/App/dtml/cpContents.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,44 @@

<main class="container-fluid">

<p class="form-help mt-4">
The Control Panel provides access to system information.
</p>
<p class="form-help mt-4">
The Control Panel provides access to system information.
</p>

<table class="table">
<tr>
<th class="text-muted">Zope Version</th>
<td class="code">&dtml-version_txt;</td>
</tr>
<tr>
<th class="text-muted">Python Version</th>
<td class="code">&dtml-sys_version;</td>
</tr>
<tr>
<th class="text-muted">System Platform</th>
<td class="code">&dtml-sys_platform;</td>
</tr>
<tr>
<th class="text-muted">INSTANCE_HOME</th>
<td class="code">&dtml-getINSTANCE_HOME;</td>
</tr>
<tr>
<th class="text-muted">CLIENT_HOME</th>
<td class="code">&dtml-getCLIENT_HOME;</th>
</tr>
<tr>
<th class="text-muted">Debug mode</th>
<td class="code">&dtml-debug_mode;</td>
</tr>
<tr>
<th class="text-muted">Process Id</th>
<td class="code">&dtml-process_id;</td>
</tr>
</table>
<table class="table">
<tr>
<th class="text-muted">Zope Version</th>
<td class="code">&dtml-version_txt;</td>
</tr>
<tr>
<th class="text-muted">Python Version</th>
<td class="code">&dtml-sys_version;</td>
</tr>
<tr>
<th class="text-muted">System Platform</th>
<td class="code">&dtml-sys_platform;</td>
</tr>
<tr>
<th class="text-muted">INSTANCE_HOME</th>
<td class="code">&dtml-getINSTANCE_HOME;</td>
</tr>
<tr>
<th class="text-muted">CLIENT_HOME</th>
<td class="code">&dtml-getCLIENT_HOME;</th>
</tr>
<tr>
<th class="text-muted">Debug mode</th>
<td class="code">&dtml-debug_mode;</td>
</tr>
<tr>
<th class="text-muted">Process Id</th>
<td class="code">&dtml-process_id;</td>
</tr>
<tr>
<th class="text-muted">Running For</th>
<td class="code">&dtml-process_time;</td>
</tr>
</table>

</main>

Expand Down
45 changes: 45 additions & 0 deletions src/App/tests/test_ApplicationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import sys
import tempfile
import time
import unittest

import Testing.ZopeTestCase
Expand Down Expand Up @@ -92,6 +93,35 @@ def test_holds_db(self):
self.assertTrue(fc.db() is db)


class ConfigurationViewerTests(ConfigTestBase, unittest.TestCase):

def _getTargetClass(self):
from App.ApplicationManager import ConfigurationViewer
return ConfigurationViewer

def _makeOne(self):
return self._getTargetClass()()

def test_defaults(self):
cv = self._makeOne()
self.assertEqual(cv.id, 'Configuration')
self.assertEqual(cv.meta_type, 'Configuration Viewer')
self.assertEqual(cv.title, 'Configuration Viewer')

def test_manage_getSysPath(self):
cv = self._makeOne()
self.assertEqual(cv.manage_getSysPath(), sorted(sys.path))

def test_manage_getConfiguration(self):
from App.config import getConfiguration
cv = self._makeOne()
cfg = getConfiguration()

for info_dict in cv.manage_getConfiguration():
self.assertEqual(info_dict['value'],
str(getattr(cfg, info_dict['name'])))


class DatabaseChooserTests(ConfigTestBase, unittest.TestCase):

def _getTargetClass(self):
Expand Down Expand Up @@ -230,6 +260,21 @@ def test_getCLIENT_HOME(self):
cldir = config.clienthome = self._makeTempdir()
self.assertEqual(am.getCLIENT_HOME(), cldir)

def test_process_time(self):
am = self._makeOne()
now = time.time()

measure, unit = am.process_time(_when=now).strip().split()
self.assertEqual(unit, 'sec')

ret_str = am.process_time(_when=now + 90061).strip()
secs = 1 + int(measure)
self.assertEqual(ret_str, '1 day 1 hour 1 min %i sec' % secs)

ret_str = am.process_time(_when=now + 180122).strip()
secs = 2 + int(measure)
self.assertEqual(ret_str, '2 days 2 hours 2 min %i sec' % secs)


class AltDatabaseManagerTests(unittest.TestCase):

Expand Down
3 changes: 2 additions & 1 deletion src/App/www/chooseDatabase.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<h1 tal:replace="structure context/manage_page_header" />
<h2 tal:replace="structure context/manage_tabs" />
<h2 tal:define="management_view string:Databases"
tal:replace="structure context/manage_tabs" />

<main class="container-fluid">

Expand Down
4 changes: 4 additions & 0 deletions src/zmi/styles/resources/zmi_base.css
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ textarea.zmi-code {
font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
}

.code.syspath {
font-size: .75em;
}

/* MANAGE MENU */

table#menu_title,
Expand Down

0 comments on commit 42a2b06

Please sign in to comment.