cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Builds.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport os;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncimport unittest;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager import config;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core import coreconsts;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelDataBaseTestCase, ModelLogicBase, TMExceptionBase;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildCategoryData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync A build category.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksIdAttr = 'idBuildCategory';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idBuildCategory = 'BuildCategory_idBuildCategory';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sProduct = 'BuildCategory_sProduct';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sRepository = 'BuildCategory_sRepository';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sBranch = 'BuildCategory_sBranch';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sType = 'BuildCategory_sType';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_asOsArches = 'BuildCategory_asOsArches';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = ['idBuildCategory', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuildCategory = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sProduct = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sRepository = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBranch = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sType = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asOsArches = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Re-initializes the object from a SELECT * FROM BuildCategories row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if aoRow is None.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('BuildCategory not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuildCategory = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sProduct = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sRepository = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBranch = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sType = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asOsArches = sorted(aoRow[5]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idBuildCategory, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize from the database, given the ID of a row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = tsNow; _ = sPeriodBack; # No history in this table.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute('SELECT * FROM BuildCategories WHERE idBuildCategory = %s', (idBuildCategory,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = oDb.fetchOne()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('idBuildCategory=%s not found' % (idBuildCategory, ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromValues(self, sProduct, sRepository, sBranch, sType, asOsArches, idBuildCategory = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitializes form a set of values.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuildCategory = idBuildCategory;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sProduct = sProduct;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sRepository = sRepository;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBranch = sBranch;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sType = sType;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asOsArches = asOsArches;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Handle sType and asOsArches specially.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sAttr == 'sType':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oNewValue, sError) = ModelDataBase._validateAndConvertAttribute(self, sAttr, sParam, oValue,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoNilValues, fAllowNull, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sError is None and self.sType.lower() != self.sType:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sError = 'Invalid build type value';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif sAttr == 'asOsArches':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oNewValue, sError) = self.validateListOfStr(oValue, aoNilValues = aoNilValues, fAllowNull = fAllowNull,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asValidValues = coreconsts.g_kasOsDotCpusAll);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sError is not None and oNewValue is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oNewValue = sorted(oNewValue); # Must be sorted!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return ModelDataBase._validateAndConvertAttribute(self, sAttr, sParam, oValue, aoNilValues, fAllowNull, oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return (oNewValue, sError);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def matchesOsArch(self, sOs, sArch):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Checks if the build matches the given OS and architecture. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sOs + '.' + sArch in self.asOsArches:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sOs + '.noarch' in self.asOsArches:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if 'os-agnostic.' + sArch in self.asOsArches:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if 'os-agnostic.noarch' in self.asOsArches:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildCategoryLogic(ModelLogicBase): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Build categories database logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches testboxes for listing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of UserAccountData items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = tsNow;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sProduct, sRepository, sBranch, sType, idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (cMaxRows, iStart,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for _ in range(self._oDb.getRowCount()):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(BuildCategoryData().initFromDbRow(self._oDb.fetchOne()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRows;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForCombo(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Build Categories for a combo box.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of (value [idBuildCategory], drop-down-name [info],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync hover-text [info]) tuples.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sProduct, sBranch, sType, asOsArches')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData = BuildCategoryData().initFromDbRow(aoRow)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sInfo = '%s / %s / %s / %s' % \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oData.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ', '.join(oData.asOsArches))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Make short info string if necessary
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sInfo = sInfo if len(sInfo) < 70 else (sInfo[:70] + '...')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oInfoItem = (oData.idBuildCategory, sInfo, sInfo)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(oInfoItem)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oData, uidAuthor = None, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Standard method for adding a build category.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Lazy bird warning! Reuse the soft addBuildCategory method.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.addBuildCategory(oData, fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = uidAuthor;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def removeEntry(self, uidAuthor, idBuildCategory, fCascade = False, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tries to delete the build category.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Note! Does not implement cascading. This is intentional!
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check that the build category isn't used by anyone.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT COUNT(idBuild)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuildCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idBuildCategory,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cBuilds = self._oDb.fetchOne()[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if cBuilds > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Build category #%d is used by %d builds and can therefore not be deleted.'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (idBuildCategory, cBuilds,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Ok, it's not used, so just delete it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # (No history on this table. This code is for typos.)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('DELETE FROM Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuildCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idBuildCategory,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = uidAuthor; _ = fCascade;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Other methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def tryFetch(self, idBuildCategory):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Try fetch the build category with the given ID.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns BuildCategoryData instance if found, None if not found.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync May raise exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuildCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idBuildCategory,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aaoRows) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aaoRows) != 1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise self._oDb.integrityException('Duplicates in BuildCategories: %s' % (aaoRows,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return BuildCategoryData().initFromDbRow(aaoRows[0])
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def tryFindByData(self, oData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Tries to find the matching build category from the sProduct, sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sType and asOsArches members of oData.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a valid build category ID and an updated oData object if found.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns None and unmodified oData object if not found.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync May raise exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE sProduct = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sRepository = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sBranch = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sType = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND asOsArches = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( oData.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sRepository,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sorted(oData.asOsArches),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aaoRows) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aaoRows) > 1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise self._oDb.integrityException('Duplicates in BuildCategories: %s' % (aaoRows,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.initFromDbRow(aaoRows[0]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oData.idBuildCategory;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addBuildCategory(self, oData, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Add Build Category record into the database if needed, returning updated oData.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on input and database errors.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check BuildCategoryData before do anything
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dDataErrors = oData.validateAndConvert(self._oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dDataErrors) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Invalid data passed to addBuildCategory(): %s' % (dDataErrors,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Does it already exist?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.tryFindByData(oData) is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # No, We'll have to add it.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO BuildCategories (sProduct, sRepository, sBranch, sType, asOsArches)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'RETURNING idBuildCategory'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( oData.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sRepository,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sorted(oData.asOsArches),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.idBuildCategory = self._oDb.fetchOne()[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync A build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksIdAttr = 'idBuild';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idBuild = 'Build_idBuild';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsCreated = 'Build_tsCreated';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'Build_tsEffective';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsExpire = 'Build_tsExpire';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_uidAuthor = 'Build_uidAuthor';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idBuildCategory = 'Build_idBuildCategory';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_iRevision = 'Build_iRevision';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sVersion = 'Build_sVersion';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sLogUrl = 'Build_sLogUrl';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sBinaries = 'Build_sBinaries';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_fBinariesDeleted = 'Build_fBinariesDeleted';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = ['idBuild', 'tsCreated', 'tsEffective', 'tsExpire', 'uidAuthor', 'tsCreated', 'sLogUrl'];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuild = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsCreated = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuildCategory = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.iRevision = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sVersion = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sLogUrl = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBinaries = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fBinariesDeleted = False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Re-initializes the object from a SELECT * FROM Builds row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if aoRow is None.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Build not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuild = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsCreated = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = aoRow[2];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = aoRow[3];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = aoRow[4];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idBuildCategory = aoRow[5];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.iRevision = aoRow[6];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sVersion = aoRow[7];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sLogUrl = aoRow[8];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sBinaries = aoRow[9];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.fBinariesDeleted = aoRow[10];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idBuild, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Initialize from the database, given the ID of a row.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuild = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idBuild,), tsNow, sPeriodBack));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = oDb.fetchOne()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('idBuild=%s not found (tsNow=%s sPeriodBack=%s)' % (idBuild, tsNow, sPeriodBack,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def areFilesStillThere(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Try check if the build files are still there.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True if they are, None if we cannot tell, and False if one or
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync more are missing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if self.fBinariesDeleted:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return False;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for sBinary in self.sBinaries.split(','):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sBinary = sBinary.strip();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(sBinary) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync continue;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Same URL tests as in webutils.downloadFile().
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if sBinary.startswith('http://') \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or sBinary.startswith('https://') \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync or sBinary.startswith('ftp://'):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # URL - don't bother trying to verify that (we don't use it atm).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # File.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if config.g_ksBuildBinRootDir is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sFullPath = os.path.join(config.g_ksBuildBinRootDir, sBinary);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = os.path.isfile(sFullPath);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not fRc \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and not os.path.isfile(os.path.join(config.g_ksBuildBinRootDir, config.g_ksBuildBinRootFile)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = None; # Root file missing, so the share might not be mounted correctly.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fRc is not True:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return fRc;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildDataEx(BuildData):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Complete data set.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync BuildData.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCat = None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from a SELECT Builds.*, BuildCategories.* FROM Builds, BuildCategories query.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if aoRow is None.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Build not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync BuildData.initFromDbRow(self, aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.oCat = BuildCategoryData().initFromDbRow(aoRow[11:]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbWithId(self, oDb, idBuild, tsNow = None, sPeriodBack = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Reinitialize from database given a row ID.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception on database error or if the ID is invalid.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oDb.execute(self.formatSimpleNowAndPeriodQuery(oDb,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SELECT Builds.*, BuildCategories.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuild = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.idBuildCategory = BuildCategories.idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( idBuild,), tsNow, sPeriodBack, 'Builds.'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = oDb.fetchOne()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('idBuild=%s not found (tsNow=%s sPeriodBack=%s)' % (idBuild, tsNow, sPeriodBack,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self.initFromDbRow(aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def convertFromParamNull(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Not implemented');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isEqual(self, oOther):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Not implemented');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildLogic(ModelLogicBase): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Build database logic (covers build categories as well as builds).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Standard methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches builds for listing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of BuildDataEx items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE Builds.idBuildCategory = BuildCategories.idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY tsCreated DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (cMaxRows, iStart,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE Builds.idBuildCategory = BuildCategories.idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY tsCreated DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsNow, tsNow, cMaxRows, iStart,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for _ in range(self._oDb.getRowCount()):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(BuildDataEx().initFromDbRow(self._oDb.fetchOne()));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRows;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oBuildData, uidAuthor = None, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Adds the build to the database, optionally adding the build category if
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync a BuildDataEx object used and it's necessary.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns updated data object. Raises exception on failure.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Find/Add the build category if specified.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if isinstance(oBuildData, BuildDataEx) \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync and oBuildData.idBuildCategory is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync BuildCategoryLogic(self._oDb).addBuildCategory(oBuildData.oCat, fCommit = False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.idBuildCategory = oBuildData.oCat.idBuildCategory;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add the build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO Builds (uidAuthor,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idBuildCategory,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' iRevision,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sVersion,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sLogUrl,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sBinaries,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' fBinariesDeleted)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'RETURNING idBuild, tsCreated\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( uidAuthor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.idBuildCategory,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.sVersion,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.sLogUrl,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.sBinaries,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.fBinariesDeleted,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRow = self._oDb.fetchOne();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.idBuild = aoRow[0];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildData.tsCreated = aoRow[1];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBuildData;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def editEntry(self, oData, uidAuthor = None, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Modify database record"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Validate input and get current data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync dErrors = oData.validateAndConvert(self._oDb);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(dErrors) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('editEntry invalid input: %s' % (dErrors,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oOldData = BuildData().initFromDbWithId(self._oDb, oData.idBuild);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Do the work.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not oData.isEqualEx(oOldData, [ 'tsEffective', 'tsExpire', 'uidAuthor' ]):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._historizeBuild(oData.idBuild);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO Builds (uidAuthor,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idBuild,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' tsCreated,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idBuildCategory,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' iRevision,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sVersion,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sLogUrl,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sBinaries,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' fBinariesDeleted)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'RETURNING idBuild, tsCreated\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , ( uidAuthor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.idBuild,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.tsCreated,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.idBuildCategory,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sVersion,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sLogUrl,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.sBinaries,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.fBinariesDeleted,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def removeEntry(self, uidAuthor, idBuild, fCascade = False, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # No non-historic refs here, so just go ahead and expire the build.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = fCascade;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync _ = uidAuthor; ## @todo record deleter.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._historizeBuild(idBuild, None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Other methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def tryFindSameBuildForOsArch(self, oBuildEx, sOs, sCpuArch):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Attempts to find a matching build for the given OS.ARCH. May return
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync the input build if if matches.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns BuildDataEx instance if found, None if none. May raise
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBuildEx.oCat.matchesOsArch(sOs, sCpuArch):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBuildEx;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT Builds.*, BuildCategories.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE BuildCategories.sProduct = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildCategories.sBranch = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildCategories.sType = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND ( %s = ANY(BuildCategories.asOsArches)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s = ANY(BuildCategories.asOsArches)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s = ANY(BuildCategories.asOsArches))\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.idBuildCategory = BuildCategories.idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.iRevision = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.sRelease = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.fBinariesDeleted IS FALSE\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY tsCreated DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT 4096\n' # stay sane.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oBuildEx.oCat.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.oCat.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.oCat.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s.%s' % (sOs, sCpuArch),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '%s.noarch' % (sOs,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'os-agnostic.%s' % (sCpuArch,),
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'os-agnostic.noarch',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.sRelease,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildExRet = BuildDataEx().initFromDbRow(self, aoRow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if not self.isBuildBlacklisted(oBuildExRet):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBuildExRet;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def isBuildBlacklisted(self, oBuildEx):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Checks if the given build is blacklisted
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns True/False. May raise exception on database error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsAgnosticArch = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsNoArch = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for i in range(len(oBuildEx.oCat.asOsArches)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asParts = oBuildEx.oCat.asOsArches[i].split('.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(asParts) != 2 or len(asParts[0]) == 0 or len(asParts[1]) == 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise self._oDb.integrityException('Bad build asOsArches value: %s (idBuild=%s idBuildCategory=%s)'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % (oBuildEx.asOsArches[i], oBuildEx.idBuild, oBuildEx.idBuildCategory));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsNoArch.append(asParts[0] + '.noarch');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsNoArch.append('os-agnostic.' + asParts[1]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT COUNT(*)\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM BuildBlacklist\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE BuildBlacklist.tsExpire > CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildBlacklist.tsEffective <= CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildBlacklist.sProduct = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildBlacklist.sBranch = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND ( BuildBlacklist.asTypes is NULL\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s = ANY(BuildBlacklist.asTypes))\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND ( BuildBlacklist.asOsArches is NULL\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s && BuildBlacklist.asOsArches\n' ## @todo check array rep! Need overload?
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s && BuildBlacklist.asOsArches\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s && BuildBlacklist.asOsArches\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' OR %s = ANY(BuildBlacklist.asOsArches))\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildBlacklist.iFirstRevision <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND BuildBlacklist.iLastRevision >= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (oBuildEx.oCat.sProduct,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.oCat.sBranch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.oCat.sType,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.oCat.asOsArches,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsAgnosticArch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync asOsNoArch,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'os-agnostic.noarch',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBuildEx.iRevision,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ) );
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._oDb.fetchOne()[0] > 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getById(self, idBuild):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Get build record by its id
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT Builds.*, BuildCategories.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE Builds.idBuild=%s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.idBuildCategory=BuildCategories.idBuildCategory\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsExpire = \'infinity\'::TIMESTAMP\n', (idBuild,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aRows) not in (0, 1):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Found more than one build with the same credentials. Database structure is corrupted.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return BuildDataEx().initFromDbRow(aRows[0])
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except IndexError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getAll(self, tsEffective = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of all builds.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of BuildDataEx instances.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT Builds.*, BuildCategories.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE Builds.tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.idBuildCategory=BuildCategories.idBuildCategory')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT Builds.*, BuildCategories.*\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds, BuildCategories\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE Builds.tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.tsEffective <= %s'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND Builds.idBuildCategory=BuildCategories.idBuildCategory'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsEffective, tsEffective))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(BuildDataEx().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def markDeletedByBinaries(self, sBinaries, fCommit = False):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Marks zero or more builds deleted given the build binaries.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns the number of affected builds.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Fetch a list of affected build IDs (generally 1 build), and used the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # editEntry method to do the rest. This isn't 100% optimal, but it's
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # short and simple, the main effort is anyway the first query.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idBuild\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE sBinaries = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND fBinariesDeleted = FALSE\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (sBinaries,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aaoRows = self._oDb.fetchAll();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in aaoRows:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData = BuildData().initFromDbWithId(self._oDb, aoRow[0]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync assert not oData.fBinariesDeleted;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oData.fBinariesDeleted = True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.editEntry(oData, fCommit = False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.maybeCommit(fCommit);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return len(aaoRows);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Internal helpers.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def _historizeBuild(self, idBuild, tsExpire = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Historizes the current entry for the specified build. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsExpire is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuild = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idBuild,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE Builds\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idBuild = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsExpire, idBuild,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Unit testing.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# pylint: disable=C0111
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildCategoryDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [BuildCategoryData(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass BuildDataTestCase(ModelDataBaseTestCase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def setUp(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.aoSamples = [BuildData(),];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncif __name__ == '__main__':
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync unittest.main();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # not reached.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync