def _processTestSet(self, idTestSet, asFiles, sCurDir): """ Worker for processDir. Same return codes as processDir. """ sBaseFilename = os.path.join(sCurDir, 'TestSet-%d' % (idTestSet, )) if sBaseFilename[0:2] == ('.' + os.path.sep): sBaseFilename = sBaseFilename[2:] sSrcFileBase = os.path.join(self.sSrcDir, sBaseFilename + '-') # # Skip the file if the test set is still running. # But delete them if the testset is not found. # oTestSet = self.oTestSetLogic.tryFetch(idTestSet) if oTestSet is not None and sBaseFilename != oTestSet.sBaseFilename: self.warning('TestSet %d: Deleting because sBaseFilename differs: "%s" (disk) vs "%s" (db)' \ % (idTestSet, sBaseFilename, oTestSet.sBaseFilename,)) oTestSet = None if oTestSet is not None: if oTestSet.enmStatus == TestSetData.ksTestStatus_Running: self.dprint('Skipping test set #%d, still running' % (idTestSet, )) return True # # If we have a zip file already, don't try recreate it as we might # have had trouble removing the source files. # sDstDirPath = os.path.join(self.sDstDir, sCurDir) sZipFileNm = os.path.join(sDstDirPath, 'TestSet-%d.zip' % (idTestSet, )) if not os.path.exists(sZipFileNm): # # Create zip file with all testset files as members. # self.dprint('TestSet %d: Creating %s...' % ( idTestSet, sZipFileNm, )) if not self.fDryRun: if not os.path.exists(sDstDirPath): os.makedirs(sDstDirPath, 0o755) utils.noxcptDeleteFile(sZipFileNm + '.tmp') oZipFile = zipfile.ZipFile(sZipFileNm + '.tmp', 'w', zipfile.ZIP_DEFLATED, allowZip64=True) for sFile in asFiles: sSuff = os.path.splitext(sFile)[1] if sSuff in [ '.png', '.webm', '.gz', '.bz2', '.zip', '.mov', '.avi', '.mpg', '.gif', '.jpg' ]: ## @todo Consider storing these files outside the zip if they are a little largish. self.dprint('TestSet %d: Storing %s...' % (idTestSet, sFile)) oZipFile.write(sSrcFileBase + sFile, sFile, zipfile.ZIP_STORED) else: self.dprint('TestSet %d: Deflating %s...' % (idTestSet, sFile)) oZipFile.write(sSrcFileBase + sFile, sFile, zipfile.ZIP_DEFLATED) oZipFile.close() # # .zip.tmp -> .zip. # utils.noxcptDeleteFile(sZipFileNm) os.rename(sZipFileNm + '.tmp', sZipFileNm) #else: Dry run. else: self.dprint('TestSet %d: zip file exists already (%s)' % ( idTestSet, sZipFileNm, )) # # Delete the files. # fRc = True if self.fVerbose: self.dprint('TestSet %d: deleting file: %s' % (idTestSet, asFiles)) if not self.fDryRun: for sFile in asFiles: if utils.noxcptDeleteFile(sSrcFileBase + sFile) is False: self.warning('TestSet %d: Failed to delete "%s" (%s)' % ( idTestSet, sFile, sSrcFileBase + sFile, )) fRc = False return fRc
def _processTestSet(self, idTestSet, asFiles, sCurDir): """ Worker for processDir. Same return codes as processDir. """ sBaseFilename = os.path.join(sCurDir, 'TestSet-%d' % (idTestSet,)); if sBaseFilename[0:2] == ('.' + os.path.sep): sBaseFilename = sBaseFilename[2:]; sSrcFileBase = os.path.join(self.sSrcDir, sBaseFilename + '-'); # # Skip the file if the test set is still running. # But delete them if the testset is not found. # oTestSet = self.oTestSetLogic.tryFetch(idTestSet); if oTestSet is not None and sBaseFilename != oTestSet.sBaseFilename: self.warning('TestSet %d: Deleting because sBaseFilename differs: "%s" (disk) vs "%s" (db)' \ % (idTestSet, sBaseFilename, oTestSet.sBaseFilename,)); oTestSet = None; if oTestSet is not None: if oTestSet.enmStatus == TestSetData.ksTestStatus_Running: self.dprint('Skipping test set #%d, still running' % (idTestSet,)); return True; # # If we have a zip file already, don't try recreate it as we might # have had trouble removing the source files. # sDstDirPath = os.path.join(self.sDstDir, sCurDir); sZipFileNm = os.path.join(sDstDirPath, 'TestSet-%d.zip' % (idTestSet,)); if not os.path.exists(sZipFileNm): # # Create zip file with all testset files as members. # self.dprint('TestSet %d: Creating %s...' % (idTestSet, sZipFileNm,)); if not self.fDryRun: if not os.path.exists(sDstDirPath): os.makedirs(sDstDirPath, 0o755); utils.noxcptDeleteFile(sZipFileNm + '.tmp'); oZipFile = zipfile.ZipFile(sZipFileNm + '.tmp', 'w', zipfile.ZIP_DEFLATED, allowZip64 = True); for sFile in asFiles: sSuff = os.path.splitext(sFile)[1]; if sSuff in [ '.png', '.webm', '.gz', '.bz2', '.zip', '.mov', '.avi', '.mpg', '.gif', '.jpg' ]: ## @todo Consider storing these files outside the zip if they are a little largish. self.dprint('TestSet %d: Storing %s...' % (idTestSet, sFile)); oZipFile.write(sSrcFileBase + sFile, sFile, zipfile.ZIP_STORED); else: self.dprint('TestSet %d: Deflating %s...' % (idTestSet, sFile)); oZipFile.write(sSrcFileBase + sFile, sFile, zipfile.ZIP_DEFLATED); oZipFile.close(); # # .zip.tmp -> .zip. # utils.noxcptDeleteFile(sZipFileNm); os.rename(sZipFileNm + '.tmp', sZipFileNm); #else: Dry run. else: self.dprint('TestSet %d: zip file exists already (%s)' % (idTestSet, sZipFileNm,)); # # Delete the files. # fRc = True; if self.fVerbose: self.dprint('TestSet %d: deleting file: %s' % (idTestSet, asFiles)); if not self.fDryRun: for sFile in asFiles: if utils.noxcptDeleteFile(sSrcFileBase + sFile) is False: self.warning('TestSet %d: Failed to delete "%s" (%s)' % (idTestSet, sFile, sSrcFileBase + sFile,)); fRc = False; return fRc;