# -*- coding: utf-8 -*-
# $Id: wuimain.py 65090 2017-01-03 21:50:35Z vboxsync $
"""
Test Manager Core - WUI - The Main page.
"""
__copyright__ = \
"""
Copyright (C) 2012-2016 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
you can redistribute it and/or modify it under the terms of the GNU
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.
"""
__version__ = "$Revision: 65090 $"
# Standard Python imports.
# Validation Kit imports.
from testmanager import config;
from testmanager.core.base import TMExceptionBase, TMTooManyRows;
from testmanager.webui.wuibase import WuiDispatcherBase, WuiException;
from testmanager.webui.wuicontentbase import WuiTmLink;
from common import webutils, utils;
class WuiMain(WuiDispatcherBase):
"""
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.
ksScriptName = 'index.py'
## @name Actions
## @{
ksActionResultsUnGrouped = 'ResultsUnGrouped'
ksActionResultsGroupedBySchedGroup = 'ResultsGroupedBySchedGroup'
ksActionResultsGroupedByTestGroup = 'ResultsGroupedByTestGroup'
ksActionResultsGroupedByBuildRev = 'ResultsGroupedByBuildRev'
ksActionResultsGroupedByBuildCat = 'ResultsGroupedByBuildCat'
ksActionResultsGroupedByTestBox = 'ResultsGroupedByTestBox'
ksActionResultsGroupedByTestCase = 'ResultsGroupedByTestCase'
ksActionResultsGroupedByOS = 'ResultsGroupedByOS'
ksActionResultsGroupedByArch = 'ResultsGroupedByArch'
ksActionTestSetDetails = 'TestSetDetails';
ksActionTestResultDetails = ksActionTestSetDetails;
ksActionTestSetDetailsFromResult = 'TestSetDetailsFromResult'
ksActionTestResultFailureDetails = 'TestResultFailureDetails'
ksActionTestResultFailureAdd = 'TestResultFailureAdd'
ksActionTestResultFailureAddPost = 'TestResultFailureAddPost'
ksActionTestResultFailureEdit = 'TestResultFailureEdit'
ksActionTestResultFailureEditPost = 'TestResultFailureEditPost'
ksActionTestResultFailureDoRemove = 'TestResultFailureDoRemove'
ksActionViewLog = 'ViewLog'
ksActionGetFile = 'GetFile'
ksActionReportSummary = 'ReportSummary';
ksActionReportRate = 'ReportRate';
ksActionReportTestCaseFailures = 'ReportTestCaseFailures';
ksActionReportTestBoxFailures = 'ReportTestBoxFailures';
ksActionReportFailureReasons = 'ReportFailureReasons';
ksActionGraphWiz = 'GraphWiz';
ksActionVcsHistoryTooltip = 'VcsHistoryTooltip';
## @}
## @name Standard report parameters
## @{
ksParamReportPeriods = 'cPeriods';
ksParamReportPeriodInHours = 'cHoursPerPeriod';
ksParamReportSubject = 'sSubject';
ksParamReportSubjectIds = 'SubjectIds';
## @}
## @name Graph Wizard parameters
## Common parameters: ksParamReportPeriods, ksParamReportPeriodInHours, ksParamReportSubjectIds,
## ksParamReportSubject, ksParamEffectivePeriod, and ksParamEffectiveDate.
## @{
ksParamGraphWizTestBoxIds = 'aidTestBoxes';
ksParamGraphWizBuildCatIds = 'aidBuildCats';
ksParamGraphWizTestCaseIds = 'aidTestCases';
ksParamGraphWizSepTestVars = 'fSepTestVars';
ksParamGraphWizImpl = 'enmImpl';
ksParamGraphWizWidth = 'cx';
ksParamGraphWizHeight = 'cy';
ksParamGraphWizDpi = 'dpi';
ksParamGraphWizFontSize = 'cPtFont';
ksParamGraphWizErrorBarY = 'fErrorBarY';
ksParamGraphWizMaxErrorBarY = 'cMaxErrorBarY';
ksParamGraphWizMaxPerGraph = 'cMaxPerGraph';
ksParamGraphWizXkcdStyle = 'fXkcdStyle';
ksParamGraphWizTabular = 'fTabular';
ksParamGraphWizSrcTestSetId = 'idSrcTestSet';
## @}
## @name Graph implementations values for ksParamGraphWizImpl.
## @{
ksGraphWizImpl_Default = 'default';
ksGraphWizImpl_Matplotlib = 'matplotlib';
ksGraphWizImpl_Charts = 'charts';
kasGraphWizImplValid = [ ksGraphWizImpl_Default, ksGraphWizImpl_Matplotlib, ksGraphWizImpl_Charts];
kaasGraphWizImplCombo = [
( ksGraphWizImpl_Default, 'Default' ),
( ksGraphWizImpl_Matplotlib, 'Matplotlib (server)' ),
( ksGraphWizImpl_Charts, 'Google Charts (client)'),
];
## @}
## @name Log Viewer parameters.
## @{
ksParamLogSetId = 'LogViewer_idTestSet';
ksParamLogFileId = 'LogViewer_idFile';
ksParamLogChunkSize = 'LogViewer_cbChunk';
ksParamLogChunkNo = 'LogViewer_iChunk';
## @}
## @name File getter parameters.
## @{
ksParamGetFileSetId = 'GetFile_idTestSet';
ksParamGetFileId = 'GetFile_idFile';
ksParamGetFileDownloadIt = 'GetFile_fDownloadIt';
## @}
## @name VCS history parameters.
## @{
ksParamVcsHistoryRepository = 'repo';
ksParamVcsHistoryRevision = 'rev';
ksParamVcsHistoryEntries = 'cEntries';
## @}
## @name Test result listing parameters.
## @{
## If this param is specified, then show only results for this member when results grouped by some parameter.
ksParamGroupMemberId = 'GroupMemberId'
## Optional parameter for indicating whether to restrict the listing to failures only.
ksParamOnlyFailures = 'OnlyFailures';
## The sheriff parameter for getting failures needing a reason or two assigned to them.
ksParamOnlyNeedingReason = 'OnlyNeedingReason';
## Result listing sorting.
ksParamTestResultsSortBy = 'enmSortBy'
## @}
## Effective time period. one of the first column values in kaoResultPeriods.
ksParamEffectivePeriod = 'sEffectivePeriod'
## Test result period values.
kaoResultPeriods = [
( '1 hour', '1 hour', 1 ),
( '2 hours', '2 hours', 2 ),
( '3 hours', '3 hours', 3 ),
( '6 hours', '6 hours', 6 ),
( '12 hours', '12 hours', 12 ),
( '1 day', '1 day', 24 ),
( '2 days', '2 days', 48 ),
( '3 days', '3 days', 72 ),
( '1 week', '1 week', 168 ),
( '2 weeks', '2 weeks', 336 ),
( '3 weeks', '3 weeks', 504 ),
( '1 month', '1 month', 31 * 24 ), # The approx hour count varies with the start date.
( '2 months', '2 months', (31 + 31) * 24 ), # Using maximum values.
( '3 months', '3 months', (31 + 30 + 31) * 24 ),
( '6 months', '6 months', (31 + 31 + 30 + 31 + 30 + 31) * 24 ),
( '1 year', '1 year', 365 * 24 ),
];
## The default test result period.
ksResultPeriodDefault = '6 hours';
def __init__(self, oSrvGlue):
WuiDispatcherBase.__init__(self, oSrvGlue, self.ksScriptName);
self._sTemplate = 'template.html'
#
# Populate the action dispatcher dictionary.
# Lambda is forbidden because of readability, speed and reducing number of imports.
#
self._dDispatch[self.ksActionResultsUnGrouped] = self._actionResultsUnGrouped;
self._dDispatch[self.ksActionResultsGroupedByTestGroup] = self._actionResultsGroupedByTestGroup;
self._dDispatch[self.ksActionResultsGroupedByBuildRev] = self._actionResultsGroupedByBuildRev;
self._dDispatch[self.ksActionResultsGroupedByBuildCat] = self._actionResultsGroupedByBuildCat;
self._dDispatch[self.ksActionResultsGroupedByTestBox] = self._actionResultsGroupedByTestBox;
self._dDispatch[self.ksActionResultsGroupedByTestCase] = self._actionResultsGroupedByTestCase;
self._dDispatch[self.ksActionResultsGroupedByOS] = self._actionResultsGroupedByOS;
self._dDispatch[self.ksActionResultsGroupedByArch] = self._actionResultsGroupedByArch;
self._dDispatch[self.ksActionResultsGroupedBySchedGroup] = self._actionResultsGroupedBySchedGroup;
self._dDispatch[self.ksActionTestSetDetails] = self._actionTestSetDetails;
self._dDispatch[self.ksActionTestSetDetailsFromResult] = self._actionTestSetDetailsFromResult;
self._dDispatch[self.ksActionTestResultFailureAdd] = self._actionTestResultFailureAdd;
self._dDispatch[self.ksActionTestResultFailureAddPost] = self._actionTestResultFailureAddPost;
self._dDispatch[self.ksActionTestResultFailureDetails] = self._actionTestResultFailureDetails;
self._dDispatch[self.ksActionTestResultFailureDoRemove] = self._actionTestResultFailureDoRemove;
self._dDispatch[self.ksActionTestResultFailureEdit] = self._actionTestResultFailureEdit;
self._dDispatch[self.ksActionTestResultFailureEditPost] = self._actionTestResultFailureEditPost;
self._dDispatch[self.ksActionViewLog] = self._actionViewLog;
self._dDispatch[self.ksActionGetFile] = self._actionGetFile;
self._dDispatch[self.ksActionReportSummary] = self._actionReportSummary;
self._dDispatch[self.ksActionReportRate] = self._actionReportRate;
self._dDispatch[self.ksActionReportTestCaseFailures] = self._actionReportTestCaseFailures;
self._dDispatch[self.ksActionReportFailureReasons] = self._actionReportFailureReasons;
self._dDispatch[self.ksActionGraphWiz] = self._actionGraphWiz;
self._dDispatch[self.ksActionVcsHistoryTooltip] = self._actionVcsHistoryTooltip;
# Legacy.
self._dDispatch['TestResultDetails'] = self._dDispatch[self.ksActionTestSetDetails];
#
# Popupate the menus.
#
# Additional URL parameters keeping for time navigation.
sExtraTimeNav = ''
dCurParams = oSrvGlue.getParameters()
if dCurParams is not None:
for sExtraParam in [ self.ksParamItemsPerPage, self.ksParamEffectiveDate, self.ksParamEffectivePeriod, ]:
if sExtraParam in dCurParams:
sExtraTimeNav += '&%s' % (webutils.encodeUrlParams({sExtraParam: dCurParams[sExtraParam]}),)
# Additional URL parameters for reports
sExtraReports = '';
if dCurParams is not None:
for sExtraParam in [ self.ksParamReportPeriods, self.ksParamReportPeriodInHours, self.ksParamEffectiveDate, ]:
if sExtraParam in dCurParams:
sExtraReports += '&%s' % (webutils.encodeUrlParams({sExtraParam: dCurParams[sExtraParam]}),)
# Shorthand to keep within margins.
sActUrlBase = self._sActionUrlBase;
sOnlyFailures = '&%s%s' % ( webutils.encodeUrlParams({self.ksParamOnlyFailures: True}), sExtraTimeNav, );
sSheriff = '&%s%s' % ( webutils.encodeUrlParams({self.ksParamOnlyNeedingReason: True}), sExtraTimeNav, );
self._aaoMenus = \
[
[
'Sheriff', sActUrlBase + self.ksActionResultsUnGrouped + sSheriff,
[
[ 'Grouped by', None ],
[ 'Ungrouped', sActUrlBase + self.ksActionResultsUnGrouped + sSheriff ],
[ 'Sched group', sActUrlBase + self.ksActionResultsGroupedBySchedGroup + sSheriff ],
[ 'Test group', sActUrlBase + self.ksActionResultsGroupedByTestGroup + sSheriff ],
[ 'Test case', sActUrlBase + self.ksActionResultsGroupedByTestCase + sSheriff ],
[ 'Testbox', sActUrlBase + self.ksActionResultsGroupedByTestBox + sSheriff ],
[ 'OS', sActUrlBase + self.ksActionResultsGroupedByOS + sSheriff ],
[ 'Architecture', sActUrlBase + self.ksActionResultsGroupedByArch + sSheriff ],
[ 'Revision', sActUrlBase + self.ksActionResultsGroupedByBuildRev + sSheriff ],
[ 'Build category', sActUrlBase + self.ksActionResultsGroupedByBuildCat + sSheriff ],
]
],
[
'Reports', sActUrlBase + self.ksActionReportSummary,
[
[ 'Summary', sActUrlBase + self.ksActionReportSummary + sExtraReports ],
[ 'Success rate', sActUrlBase + self.ksActionReportRate + sExtraReports ],
[ 'Test case failures', sActUrlBase + self.ksActionReportTestCaseFailures + sExtraReports ],
[ 'Testbox failures', sActUrlBase + self.ksActionReportTestBoxFailures + sExtraReports ],
[ 'Failure reasons', sActUrlBase + self.ksActionReportFailureReasons + sExtraReports ],
]
],
[
'Test Results', sActUrlBase + self.ksActionResultsUnGrouped + sExtraTimeNav,
[
[ 'Grouped by', None ],
[ 'Ungrouped', sActUrlBase + self.ksActionResultsUnGrouped + sExtraTimeNav ],
[ 'Sched group', sActUrlBase + self.ksActionResultsGroupedBySchedGroup + sExtraTimeNav ],
[ 'Test group', sActUrlBase + self.ksActionResultsGroupedByTestGroup + sExtraTimeNav ],
[ 'Test case', sActUrlBase + self.ksActionResultsGroupedByTestCase + sExtraTimeNav ],
[ 'Testbox', sActUrlBase + self.ksActionResultsGroupedByTestBox + sExtraTimeNav ],
[ 'OS', sActUrlBase + self.ksActionResultsGroupedByOS + sExtraTimeNav ],
[ 'Architecture', sActUrlBase + self.ksActionResultsGroupedByArch + sExtraTimeNav ],
[ 'Revision', sActUrlBase + self.ksActionResultsGroupedByBuildRev + sExtraTimeNav ],
[ 'Build category', sActUrlBase + self.ksActionResultsGroupedByBuildCat + sExtraTimeNav ],
]
],
[
'Test Failures', sActUrlBase + self.ksActionResultsUnGrouped + sOnlyFailures,
[
[ 'Grouped by', None ],
[ 'Ungrouped', sActUrlBase + self.ksActionResultsUnGrouped + sOnlyFailures ],
[ 'Sched group', sActUrlBase + self.ksActionResultsGroupedBySchedGroup + sOnlyFailures ],
[ 'Test group', sActUrlBase + self.ksActionResultsGroupedByTestGroup + sOnlyFailures ],
[ 'Test case', sActUrlBase + self.ksActionResultsGroupedByTestCase + sOnlyFailures ],
[ 'Testbox', sActUrlBase + self.ksActionResultsGroupedByTestBox + sOnlyFailures ],
[ 'OS', sActUrlBase + self.ksActionResultsGroupedByOS + sOnlyFailures ],
[ 'Architecture', sActUrlBase + self.ksActionResultsGroupedByArch + sOnlyFailures ],
[ 'Revision', sActUrlBase + self.ksActionResultsGroupedByBuildRev + sOnlyFailures ],
[ 'Build category', sActUrlBase + self.ksActionResultsGroupedByBuildCat + sOnlyFailures ],
]
],
[
'> Admin', 'admin.py?' + webutils.encodeUrlParams(self._dDbgParams), []
],
];
#
# Overriding parent methods.
#
def _generatePage(self):
"""Override parent handler in order to change page title."""
if self._sPageTitle is not None:
self._sPageTitle = 'Test Results - ' + self._sPageTitle
return WuiDispatcherBase._generatePage(self)
def _actionDefault(self):
"""Show the default admin page."""
from testmanager.webui.wuitestresult import WuiGroupedResultList;
from testmanager.core.testresults import TestResultLogic, TestResultFilter;
self._sAction = self.ksActionResultsUnGrouped
return self._actionGroupedResultsListing(TestResultLogic.ksResultsGroupingTypeNone,
TestResultLogic, TestResultFilter, WuiGroupedResultList);
def _isMenuMatch(self, sMenuUrl, sActionParam):
if super(WuiMain, self)._isMenuMatch(sMenuUrl, sActionParam):
fOnlyNeedingReason = self.getBoolParam(self.ksParamOnlyNeedingReason, fDefault = False);
if fOnlyNeedingReason:
return (sMenuUrl.find(self.ksParamOnlyNeedingReason) > 0);
fOnlyFailures = self.getBoolParam(self.ksParamOnlyFailures, fDefault = False);
return (sMenuUrl.find(self.ksParamOnlyFailures) > 0) == fOnlyFailures \
and sMenuUrl.find(self.ksParamOnlyNeedingReason) < 0;
return False;
#
# Navigation bar stuff
#
def _generateSortBySelector(self, dParams, sPreamble, sPostamble):
"""
Generate HTML code for the sort by selector.
"""
from testmanager.core.testresults import TestResultLogic;
if self.ksParamTestResultsSortBy in dParams:
enmResultSortBy = dParams[self.ksParamTestResultsSortBy];
del dParams[self.ksParamTestResultsSortBy];
else:
enmResultSortBy = TestResultLogic.ksResultsSortByRunningAndStart;
sHtmlSortBy = '
\n'
return sHtmlSortBy;
def _generateStatusSelector(self, dParams, fOnlyFailures):
"""
Generate HTML code for the status code selector. Currently very simple.
"""
dParams[self.ksParamOnlyFailures] = not fOnlyFailures;
return WuiTmLink('Show all results' if fOnlyFailures else 'Only show failed tests', '', dParams,
fBracketed = False).toHtml();
def _generateTimeSelector(self, dParams, sPreamble, sPostamble):
"""
Generate HTML code for time selector.
"""
if WuiDispatcherBase.ksParamEffectiveDate in dParams:
tsEffective = dParams[WuiDispatcherBase.ksParamEffectiveDate]
del dParams[WuiDispatcherBase.ksParamEffectiveDate]
else:
tsEffective = ''
# Forget about page No when changing a period
if WuiDispatcherBase.ksParamPageNo in dParams:
del dParams[WuiDispatcherBase.ksParamPageNo]
sHtmlTimeSelector = '\n'
return sHtmlTimeSelector
def _generateTimeWalker(self, dParams, tsEffective, sCurPeriod):
"""
Generates HTML code for walking back and forth in time.
"""
# Have to do some math here. :-/
if tsEffective is None:
self._oDb.execute('SELECT CURRENT_TIMESTAMP - \'' + sCurPeriod + '\'::interval');
tsNext = None;
tsPrev = self._oDb.fetchOne()[0];
else:
self._oDb.execute('SELECT %s::TIMESTAMP - \'' + sCurPeriod + '\'::interval,\n'
' %s::TIMESTAMP + \'' + sCurPeriod + '\'::interval',
(tsEffective, tsEffective,));
tsPrev, tsNext = self._oDb.fetchOne();
# Forget about page No when changing a period
if WuiDispatcherBase.ksParamPageNo in dParams:
del dParams[WuiDispatcherBase.ksParamPageNo]
# Format.
dParams[WuiDispatcherBase.ksParamEffectiveDate] = str(tsPrev);
sPrev = '<< ' \
% (webutils.encodeUrlParams(dParams),);
if tsNext is not None:
dParams[WuiDispatcherBase.ksParamEffectiveDate] = str(tsNext);
sNext = ' >>' \
% (webutils.encodeUrlParams(dParams),);
else:
sNext = ' >>';
return self._generateTimeSelector(self.getParameters(), sPrev, sNext);
def _generateResultPeriodSelector(self, dParams, sCurPeriod):
"""
Generate HTML code for result period selector.
"""
if self.ksParamEffectivePeriod in dParams:
del dParams[self.ksParamEffectivePeriod];
# Forget about page No when changing a period
if WuiDispatcherBase.ksParamPageNo in dParams:
del dParams[WuiDispatcherBase.ksParamPageNo]
sHtmlPeriodSelector = '\n'
return sHtmlPeriodSelector
def _generateGroupContentSelector(self, aoGroupMembers, iCurrentMember, sAltAction):
"""
Generate HTML code for group content selector.
"""
dParams = self.getParameters()
if self.ksParamGroupMemberId in dParams:
del dParams[self.ksParamGroupMemberId]
if sAltAction is not None:
if self.ksParamAction in dParams:
del dParams[self.ksParamAction];
dParams[self.ksParamAction] = sAltAction;
sHtmlSelector = '\n'
return sHtmlSelector
def _generatePagesSelector(self, dParams, cItems, cItemsPerPage, iPage):
"""
Generate HTML code for pages (1, 2, 3 ... N) selector
"""
if WuiDispatcherBase.ksParamPageNo in dParams:
del dParams[WuiDispatcherBase.ksParamPageNo]
sHrefPtr = '%s'
cNumOfPages = (cItems + cItemsPerPage - 1) / cItemsPerPage;
cPagesToDisplay = 10
cPagesRangeStart = iPage - cPagesToDisplay / 2 \
if not iPage - cPagesToDisplay / 2 < 0 else 0
cPagesRangeEnd = cPagesRangeStart + cPagesToDisplay \
if not cPagesRangeStart + cPagesToDisplay > cNumOfPages else cNumOfPages
# Adjust pages range
if cNumOfPages < cPagesToDisplay:
cPagesRangeStart = 0
cPagesRangeEnd = cNumOfPages
# 1 2 3 4...
sHtmlPager = ' \n'.join(sHrefPtr % (x, str(x + 1)) if x != iPage else str(x + 1)
for x in range(cPagesRangeStart, cPagesRangeEnd))
if cPagesRangeStart > 0:
sHtmlPager = '%s ... \n' % (sHrefPtr % (0, str(1))) + sHtmlPager
if cPagesRangeEnd < cNumOfPages:
sHtmlPager += ' ... %s\n' % (sHrefPtr % (cNumOfPages, str(cNumOfPages + 1)))
# Prev/Next (using << >> because « and » are too tiny).
if iPage > 0:
dParams[WuiDispatcherBase.ksParamPageNo] = iPage - 1
sHtmlPager = ('<< \n'
% (webutils.encodeUrlParams(dParams), )) \
+ sHtmlPager;
else:
sHtmlPager = '<< \n' + sHtmlPager
if iPage + 1 < cNumOfPages:
dParams[WuiDispatcherBase.ksParamPageNo] = iPage + 1
sHtmlPager += '\n >>\n' % (webutils.encodeUrlParams(dParams),)
else:
sHtmlPager += '\n >>\n'
return sHtmlPager
def _generateItemPerPageSelector(self, dParams, cItemsPerPage):
"""
Generate HTML code for items per page selector
"""
if WuiDispatcherBase.ksParamItemsPerPage in dParams:
del dParams[WuiDispatcherBase.ksParamItemsPerPage]
# Forced reset of the page number
dParams[WuiDispatcherBase.ksParamPageNo] = 0
sHtmlItemsPerPageSelector = '\n'
return sHtmlItemsPerPageSelector
def _generateResultNavigation(self, cItems, cItemsPerPage, iPage, tsEffective, sCurPeriod, fOnlyFailures,
sHtmlMemberSelector):
""" Make custom time navigation bar for the results. """
# Generate the elements.
sHtmlStatusSelector = self._generateStatusSelector(self.getParameters(), fOnlyFailures);
sHtmlSortBySelector = self._generateSortBySelector(self.getParameters(), '', sHtmlStatusSelector);
sHtmlPeriodSelector = self._generateResultPeriodSelector(self.getParameters(), sCurPeriod)
sHtmlTimeWalker = self._generateTimeWalker(self.getParameters(), tsEffective, sCurPeriod);
if cItems > 0:
sHtmlPager = self._generatePagesSelector(self.getParameters(), cItems, cItemsPerPage, iPage)
sHtmlItemsPerPageSelector = self._generateItemPerPageSelector(self.getParameters(), cItemsPerPage)
else:
sHtmlPager = ''
sHtmlItemsPerPageSelector = ''
# Generate navigation bar
sHtml = '
\n' \
'
\n' \
'
' + sHtmlMemberSelector + '
\n' \
'
' + sHtmlTimeWalker + '
' \
'
\n' + sHtmlPeriodSelector + '
\n' \
'
\n' \
'
\n' \
'
' + sHtmlSortBySelector + '
\n' \
'
\n' + sHtmlPager + '
\n' \
'
\n' + sHtmlItemsPerPageSelector + '
\n'\
'
\n' \
'
\n'
return sHtml
def _generateReportNavigation(self, tsEffective, cHoursPerPeriod, cPeriods):
""" Make time navigation bar for the reports. """
# The period length selector.
dParams = self.getParameters();
if WuiMain.ksParamReportPeriodInHours in dParams:
del dParams[WuiMain.ksParamReportPeriodInHours];
sHtmlPeriodLength = '';
sHtmlPeriodLength += '\n'
# The period count selector.
dParams = self.getParameters();
if WuiMain.ksParamReportPeriods in dParams:
del dParams[WuiMain.ksParamReportPeriods];
sHtmlCountOfPeriods = '';
sHtmlCountOfPeriods += '\n'
# The time walker.
sHtmlTimeWalker = self._generateTimeWalker(self.getParameters(), tsEffective, '%d hours' % (cHoursPerPeriod));
# Combine them all.
sHtml = '
\n' \
'
\n' \
'
\n' + sHtmlPeriodLength + '
\n' \
'
\n' + sHtmlTimeWalker + '
' \
'
\n' + sHtmlCountOfPeriods + '
\n' \
'
\n' \
'
\n';
return sHtml;
#
# The rest of stuff
#
def _actionGroupedResultsListing( #pylint: disable=R0914
self,
enmResultsGroupingType,
oResultsLogicType,
oResultFilterType,
oResultsListContentType):
"""
Override generic listing action.
oResultsLogicType implements getEntriesCount, fetchResultsForListing and more.
oResultFilterType is a child of ModelFilterBase.
oResultsListContentType is a child of WuiListContentBase.
"""
from testmanager.core.testresults import TestResultLogic;
cItemsPerPage = self.getIntParam(self.ksParamItemsPerPage, iMin = 2, iMax = 9999, iDefault = 128);
iPage = self.getIntParam(self.ksParamPageNo, iMin = 0, iMax = 999999, iDefault = 0);
tsEffective = self.getEffectiveDateParam();
iGroupMemberId = self.getIntParam(self.ksParamGroupMemberId, iMin = -1, iMax = 999999, iDefault = -1);
fOnlyFailures = self.getBoolParam(self.ksParamOnlyFailures, fDefault = False);
fOnlyNeedingReason = self.getBoolParam(self.ksParamOnlyNeedingReason, fDefault = False);
enmResultSortBy = self.getStringParam(self.ksParamTestResultsSortBy,
asValidValues = TestResultLogic.kasResultsSortBy,
sDefault = TestResultLogic.ksResultsSortByRunningAndStart);
oFilter = oResultFilterType().initFromParams(self);
# Get testing results period and validate it
asValidValues = [x for (x, _, _) in self.kaoResultPeriods]
sCurPeriod = self.getStringParam(self.ksParamEffectivePeriod, asValidValues = asValidValues,
sDefault = self.ksResultPeriodDefault)
assert sCurPeriod != ''; # Impossible!
self._checkForUnknownParameters()
#
# Fetch the group members.
#
# If no grouping is selected, we'll fill the grouping combo with
# testboxes just to avoid having completely useless combo box.
#
oTrLogic = TestResultLogic(self._oDb);
sAltSelectorAction = None;
if enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeNone \
or enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeTestBox:
aoTmp = oTrLogic.getTestBoxes(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set([ (x.idTestBox, '%s (%s)' % (x.sName, str(x.ip))) for x in aoTmp ])),
reverse = False, key = lambda asData: asData[1])
if enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeTestBox:
self._sPageTitle = 'Grouped by Test Box';
else:
self._sPageTitle = 'Ungrouped results';
sAltSelectorAction = self.ksActionResultsGroupedByTestBox;
aoGroupMembers.insert(0, [None, None]); # The "All" member.
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeTestGroup:
aoTmp = oTrLogic.getTestGroups(tsNow = tsEffective, sPeriod = sCurPeriod);
aoGroupMembers = sorted(list(set([ (x.idTestGroup, x.sName ) for x in aoTmp ])),
reverse = False, key = lambda asData: asData[1])
self._sPageTitle = 'Grouped by Test Group'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeBuildRev:
aoTmp = oTrLogic.getBuilds(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set([ (x.iRevision, '%s.%d' % (x.oCat.sBranch, x.iRevision)) for x in aoTmp ])),
reverse = True, key = lambda asData: asData[0])
self._sPageTitle = 'Grouped by Build'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeBuildCat:
aoTmp = oTrLogic.getBuildCategories(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set([ ( x.idBuildCategory, '%s / %s / %s / %s'
% ( x.sProduct, x.sBranch, ', '.join(x.asOsArches), x.sType) )
for x in aoTmp ])),
reverse = True, key = lambda asData: asData[1]);
self._sPageTitle = 'Grouped by Build Category'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeTestCase:
aoTmp = oTrLogic.getTestCases(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set([ (x.idTestCase, '%s' % x.sName) for x in aoTmp ])),
reverse = False, key = lambda asData: asData[1])
self._sPageTitle = 'Grouped by Test Case'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeOS:
aoTmp = oTrLogic.getOSes(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set(aoTmp)), reverse = False, key = lambda asData: asData[1]);
self._sPageTitle = 'Grouped by OS'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeArch:
aoTmp = oTrLogic.getArchitectures(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set(aoTmp)), reverse = False, key = lambda asData: asData[1]);
self._sPageTitle = 'Grouped by Architecture'
elif enmResultsGroupingType == TestResultLogic.ksResultsGroupingTypeSchedGroup:
aoTmp = oTrLogic.getSchedGroups(tsNow = tsEffective, sPeriod = sCurPeriod)
aoGroupMembers = sorted(list(set([ (x.idSchedGroup, '%s' % x.sName) for x in aoTmp ])),
reverse = False, key = lambda asData: asData[1])
self._sPageTitle = 'Grouped by Scheduling Group'
else:
raise TMExceptionBase('Unknown grouping type')
_sPageBody = ''
oContent = None
cEntriesMax = 0
_dParams = self.getParameters()
oResultLogic = oResultsLogicType(self._oDb);
for idMember, sMemberName in aoGroupMembers:
#
# 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)
or (iGroupMemberId > 0 and enmResultsGroupingType != TestResultLogic.ksResultsGroupingTypeNone) ):
continue
cEntries = oResultLogic.getEntriesCount(tsNow = tsEffective,
sInterval = sCurPeriod,
oFilter = oFilter,
enmResultsGroupingType = enmResultsGroupingType,
iResultsGroupingValue = idMember,
fOnlyFailures = fOnlyFailures,
fOnlyNeedingReason = fOnlyNeedingReason);
if cEntries == 0: # Do not display empty groups
continue
aoEntries = oResultLogic.fetchResultsForListing(iPage * cItemsPerPage,
cItemsPerPage,
tsNow = tsEffective,
sInterval = sCurPeriod,
oFilter = oFilter,
enmResultSortBy = enmResultSortBy,
enmResultsGroupingType = enmResultsGroupingType,
iResultsGroupingValue = idMember,
fOnlyFailures = fOnlyFailures,
fOnlyNeedingReason = fOnlyNeedingReason);
cEntriesMax = max(cEntriesMax, cEntries)
#
# Format them.
#
oContent = oResultsListContentType(aoEntries,
cEntries,
iPage,
cItemsPerPage,
tsEffective,
fnDPrint = self._oSrvGlue.dprint,
oDisp = self)
(_, sHtml) = oContent.show(fShowNavigation = False)
if sMemberName is not None:
_sPageBody += '