# -*- coding: utf-8 -*-
# $Id$
"""
Test Manager Core - WUI - The Main page.
"""
__copyright__ = \
"""
Copyright (C) 2012-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard Python imports.
# Validation Kit imports.
"""
WUI Main page.
Note! All cylic dependency avoiance stuff goes here in the dispatcher code,
not in the action specific code. This keeps the uglyness in one place
and reduces load time dependencies in the more critical code path.
"""
## The name of the script.
## @name Actions
## @{
## @}
## @name Standard report parameters
## @{
## @}
## @name Graph Wizard parameters
## Common parameters: ksParamReportPeriods, ksParamReportPeriodInHours, ksParamReportSubjectIds,
## ksParamReportSubject, ksParamEffectivePeriod, and ksParamEffectiveDate.
## @{
## @}
## @name Graph implementations values for ksParamGraphWizImpl.
## @{
( ksGraphWizImpl_Default, 'Default' ),
( ksGraphWizImpl_Matplotlib, 'Matplotlib (server)' ),
( ksGraphWizImpl_Charts, 'Google Charts (client)'),
];
## @}
## @name Log Viewer parameters.
## @{
## @}
## @name File getter parameters.
## @{
## @}
## @name VCS history parameters.
## @{
## @}
## Effective time period. one of the first column values in kaoResultPeriods.
## If this param is specified, then show only results for this member when results grouped by some parameter.
## Optional parameter for indicating whether to restrict the listing to failures only.
## Test result period values.
kaoResultPeriods = [
( '1 hour', 'One hour', 1 ),
( '2 hours', 'Two hours', 2 ),
( '3 hours', 'Three hours', 3 ),
( '6 hours', 'Six hours', 6 ),
( '12 hours', '12 hours', 12 ),
( '1 day', 'One day', 24 ),
( '2 days', 'Two days', 48 ),
( '3 days', 'Three days', 72 ),
( '1 week', 'One week', 168 ),
( '2 weeks', 'Two weeks', 336 ),
( '3 weeks', 'Three weeks', 504 ),
( '1 month', 'One month', 31 * 24 ), # The approx hour count varies with the start date.
( '2 months', 'Two month', (31 + 31) * 24 ), # Using maximum values.
( '3 months', 'Three month', (31 + 30 + 31) * 24 ),
( '6 months', 'Six month', (31 + 31 + 30 + 31 + 30 + 31) * 24 ),
( '1 year', 'One year', 365 * 24 ),
];
## The default test result period.
#
# Populate the action dispatcher dictionary.
#
# Use short form to avoid hitting the right margin (130) when using lambda.
#d[self.ksActionResultsUnGrouped] = lambda: self._actionResultsListing(TestResultLogic, WuiGroupedResultList)
from testmanager.webui.wuireport import WuiReportSummary, WuiReportSuccessRate, WuiReportFailureReasons;
d[self.ksActionReportSummary] = lambda: self._actionGenericReport(ReportLazyModel, WuiReportSummary);
d[self.ksActionReportRate] = lambda: self._actionGenericReport(ReportLazyModel, WuiReportSuccessRate);
d[self.ksActionReportFailureReasons] = lambda: self._actionGenericReport(ReportLazyModel, WuiReportFailureReasons);
#
# Popupate the menus.
#
# Additional URL parameters keeping for time navigation.
sExtraTimeNav = ''
if dCurParams is not None:
asActionUrlExtras = [ self.ksParamItemsPerPage, self.ksParamEffectiveDate, self.ksParamEffectivePeriod, ];
for sExtraParam in asActionUrlExtras:
if sExtraParam in dCurParams:
# Shorthand to keep within margins.
[
[
[]
],
[
[
]
],
[
[
[ 'Grouped by Scheduling Group', sActUrlBase + self.ksActionResultsGroupedBySchedGroup + sExtraTimeNav ],
]
],
[
],
];
"""Show the default admin page."""
#
# Navigation bar stuff
#
"""
Generate HTML code for the status code selector. Currently very simple.
"""
"""
Generate HTML code for time selector.
"""
else:
tsEffective = ''
# Forget about page No when changing a period
sHtmlTimeSelector = '<form name="TimeForm" method="GET">\n'
sHtmlTimeSelector += '\n <select name="%s" onchange="window.location=' % WuiDispatcherBase.ksParamEffectiveDate
sHtmlTimeSelector += '\'?%s&%s=\' + ' % (webutils.encodeUrlParams(dParams), WuiDispatcherBase.ksParamEffectiveDate)
sHtmlTimeSelector += 'this.options[this.selectedIndex].value;" title="Effective date">\n'
aoWayBackPoints = [
('+0000-00-00 00:00:00.00', 'Now', ' title="Present Day. Present Time."'), # lain :)
('-0000-00-00 01:00:00.00', 'One hour ago', ''),
('-0000-00-00 02:00:00.00', 'Two hours ago', ''),
('-0000-00-00 03:00:00.00', 'Three hours ago', ''),
('-0000-00-01 00:00:00.00', 'One day ago', ''),
('-0000-00-02 00:00:00.00', 'Two days ago', ''),
('-0000-00-03 00:00:00.00', 'Three days ago', ''),
('-0000-00-07 00:00:00.00', 'One week ago', ''),
('-0000-00-14 00:00:00.00', 'Two weeks ago', ''),
('-0000-00-21 00:00:00.00', 'Three weeks ago', ''),
('-0000-01-00 00:00:00.00', 'One month ago', ''),
('-0000-02-00 00:00:00.00', 'Two months ago', ''),
('-0000-03-00 00:00:00.00', 'Three months ago', ''),
('-0000-04-00 00:00:00.00', 'Four months ago', ''),
('-0000-05-00 00:00:00.00', 'Five months ago', ''),
('-0000-06-00 00:00:00.00', 'Half a year ago', ''),
('-0001-00-00 00:00:00.00', 'One year ago', ''),
]
if sTimestamp == tsEffective:
sHtmlTimeSelector += ' <option value="%s"%s%s>%s</option>\n' \
sHtmlTimeSelector += ' <option value="%s" selected>%s</option>\n' \
sHtmlTimeSelector += ' </select>\n';
sHtmlTimeSelector += '\n</form>\n'
return sHtmlTimeSelector
"""
Generates HTML code for walking back and forth in time.
"""
# Have to do some math here. :-/
if tsEffective is None:
tsNext = None;
else:
(tsEffective, tsEffective,));
# Forget about page No when changing a period
# Format.
sPrev = '<a href="?%s" title="One period earlier"><<</a> ' \
if tsNext is not None:
sNext = ' <a href="?%s" title="One period later">>></a>' \
else:
sNext = ' >>';
"""
Generate HTML code for result period selector.
"""
# Forget about page No when changing a period
sHtmlPeriodSelector = '<form name="PeriodForm" method="GET">\n'
sHtmlPeriodSelector += ' Period is\n'
sHtmlPeriodSelector += ' <select name="%s" onchange="window.location=' % self.ksParamEffectivePeriod
sHtmlPeriodSelector += '\'?%s&%s=\' + ' % (webutils.encodeUrlParams(dParams), self.ksParamEffectivePeriod)
sHtmlPeriodSelector += 'this.options[this.selectedIndex].value;">\n'
sHtmlPeriodSelector += ' <option value="%s"%s>%s</option>\n' \
sHtmlPeriodSelector += ' </select>\n' \
'</form>\n'
return sHtmlPeriodSelector
"""
Generate HTML code for group content selector.
"""
if sAltAction is not None:
sHtmlSelector = '<form name="GroupContentForm" method="GET">\n'
sHtmlSelector += 'this.options[this.selectedIndex].value;">\n'
sHtmlSelector += '<option value="-1">All</option>\n'
if iGroupMemberId is not None:
sHtmlSelector += ' <option value="%s"%s>%s</option>\n' \
% (iGroupMemberId,
sHtmlSelector += ' </select>\n' \
'</form>\n'
return sHtmlSelector
"""
Generate HTML code for pages (1, 2, 3 ... N) selector
"""
sHrefPtr += '%d">%s</a>'
cPagesToDisplay = 10
# Adjust pages range
if cNumOfPages < cPagesToDisplay:
cPagesRangeStart = 0
# 1 2 3 4...
if cPagesRangeStart > 0:
if cPagesRangeEnd < cNumOfPages:
if iPage > 0:
sHtmlPager = ('<a title="Previous page" href="?%s"><<</a> \n'
+ sHtmlPager;
else:
sHtmlPager += '\n <a title="Next page" href="?%s">>></a>\n' % (webutils.encodeUrlParams(dParams),)
else:
sHtmlPager += '\n >>\n'
return sHtmlPager
"""
Generate HTML code for items per page selector
"""
# Forced reset of the page number
sHtmlItemsPerPageSelector = '<form name="AgesPerPageForm" method="GET">\n' \
' Max <select name="%s" onchange="window.location=\'?%s&%s=\' + ' \
'this.options[this.selectedIndex].value;" title="Max items per page">\n' \
for iItemsPerPage in aiItemsPerPage:
sHtmlItemsPerPageSelector += ' <option value="%d" %s>%d</option>\n' \
% (iItemsPerPage,
sHtmlItemsPerPageSelector += ' </select> items per page\n' \
'</form>\n'
return sHtmlItemsPerPageSelector
def _generateResultNavigation(self, cItems, cItemsPerPage, iPage, tsEffective, sCurPeriod, fOnlyFailures,
""" Make custom time navigation bar for the results. """
# Generate the elements.
if cItems > 0:
else:
sHtmlPager = ''
# Generate navigation bar
sHtml = '<table width=100%>\n' \
'<tr>\n' \
'</tr>\n' \
'<tr>\n' \
'</tr>\n' \
'</table>\n'
return sHtml
""" Make time navigation bar for the reports. """
# The period length selector.
sHtmlPeriodLength = '';
sHtmlPeriodLength += '<form name="ReportPeriodInHoursForm" method="GET">\n' \
' Period length <select name="%s" onchange="window.location=\'?%s&%s=\' + ' \
'this.options[this.selectedIndex].value;" title="Statistics period length in hours.">\n' \
sHtmlPeriodLength += ' <option value="%d"%s>%d hour%s</option>\n' \
sHtmlPeriodLength += ' </select>\n' \
'</form>\n'
# The period count selector.
sHtmlCountOfPeriods = '';
sHtmlCountOfPeriods += '<form name="ReportPeriodsForm" method="GET">\n' \
' Periods <select name="%s" onchange="window.location=\'?%s&%s=\' + ' \
'this.options[this.selectedIndex].value;" title="Statistics periods to report.">\n' \
sHtmlCountOfPeriods += ' <option value="%d"%s>%d</option>\n' \
sHtmlCountOfPeriods += ' </select>\n' \
'</form>\n'
# The time walker.
sHtmlTimeWalker = self._generateTimeWalker(self.getParameters(), tsEffective, '%d hours' % (cHoursPerPeriod));
# Combine them all.
sHtml = '<table width=100%>\n' \
' <tr>\n' \
' </tr>\n' \
'</table>\n';
return sHtml;
#
# The rest of stuff
#
self,
"""
Override generic listing action.
oLogicType implements fetchForListing.
oListContentType is a child of WuiListContentBase.
"""
iGroupMemberId = self.getIntParam(self.ksParamGroupMemberId, iMin = -1, iMax = 999999, iDefault = -1)
# Get testing results period and validate it
#
# Fetch the group members.
#
# If no grouping is selected, we'll fill the the grouping combo with
# testboxes just to avoid having completely useless combo box.
#
sAltSelectorAction = None;
aoGroupMembers = sorted(list(set([ (x.idTestBox, '%s (%s)' % (x.sName, str(x.ip))) for x in aoTmp ])),
else:
aoGroupMembers = sorted(list(set([ (x.iRevision, '%s.%d' % (x.oCat.sBranch, x.iRevision)) for x in aoTmp ])),
else:
raise TMExceptionBase('Unknown grouping type')
_sPageBody = ''
oContent = None
cEntriesMax = 0
#
# Count and fetch entries to be displayed.
#
# Skip group members that were not specified.
if idMember != iGroupMemberId \
and ( (idMember is not None and enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeNone)
continue
continue
tsNow = tsEffective,
#
# Format them.
#
if sMemberName is not None:
_sPageBody += '<table width=100%><tr><td>'
_sPageBody += '<td><br></td>'
_sPageBody += '</tr></table>'
_sPageBody += sHtml
_sPageBody += '<br>'
#
# Complete the page by slapping navigation controls at the top and
# bottom of it.
#
if cEntriesMax > 0:
else:
return True;
"""Override parent handler in order to change page title."""
if self._sPageTitle is not None:
"""Show test case execution result details."""
try:
except TMTooManyRows:
oBuildDataEx = BuildDataEx().initFromDbWithId(self._oDb, oTestSetData.idBuild, oTestSetData.tsCreated);
try: oBuildValidationKitDataEx = BuildDataEx().initFromDbWithId(self._oDb, oTestSetData.idBuildTestSuite,
except: oBuildValidationKitDataEx = None;
oTestGroupData = TestGroupData().initFromDbWithId(self._oDb, ## @todo This bogus time wise. Bad DB design?
oTestCaseArgsDataEx = TestCaseArgsDataEx().initFromDbWithGenIdEx(self._oDb, oTestSetData.idGenTestCaseArgs,
return True
"""
Log viewer action.
"""
cbChunk = self.getIntParam(self.ksParamLogChunkSize, iMin = 256, iMax = 16777216, iDefault = 65536);
if idLogFile == 0:
else:
oContent = WuiLogViewer(oTestSet, oTestFile, cbChunk, iChunk, oDisp = self, fnDPrint = self._oSrvGlue.dprint);
return True;
"""
Get file action.
"""
#
# Get the file info and open it.
#
if idFile == 0:
else:
if oFile is None:
raise Exception(oSizeOrError);
#
# Send the file.
#
if fDownloadIt:
while True:
break;
return self.ksDispatchRcAllDone;
"""
Generic report action.
oReportType is a child of WuiReportContentBase.
oModelType is a child of ReportModelBase.
"""
cHoursPerPeriod = self.getIntParam(self.ksParamReportPeriodInHours, iMin = 1, iMax = 168, iDefault = 24);
else:
if aidSubjects is None:
dParams = \
{
};
oContent = oReportType(oModel, dParams, fSubReport = False, fnDPrint = self._oSrvGlue.dprint, oDisp = self);
return True;
"""
Graph wizard action.
"""
cPeriods = self.getIntParam(self.ksParamReportPeriods, iMin = 1, iMax = 1, iDefault = 1); # Not needed yet.
enmGraphImpl = self.getStringParam(self.ksParamGraphWizImpl, asValidValues = self.kasGraphWizImplValid,
cy = self.getIntParam(self.ksParamGraphWizHeight, iMin = 128, iMax = 8192, iDefault = int(cx * 5 / 16) );
cMaxErrorBarY = self.getIntParam(self.ksParamGraphWizMaxErrorBarY, iMin = 8, iMax = 9999999, iDefault = 18);
cMaxPerGraph = self.getIntParam(self.ksParamGraphWizMaxPerGraph, iMin = 1, iMax = 24, iDefault = 8);
dParams = \
{
};
oModel = ReportGraphModel(self._oDb, tsEffective, cPeriods, cHoursPerPeriod, sSubject, asSubjectIds,
oContent = WuiGraphWiz(oModel, dParams, fSubReport = False, fnDPrint = self._oSrvGlue.dprint, oDisp = self);
return True;
"""
Version control system history.
"""
return True;