suite.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. '''
  2. /*#############################################################################
  3. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems(R).
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. ############################################################################ */
  14. '''
  15. import os
  16. import sys
  17. import time
  18. import glob
  19. from ..util.ecl.file import ECLFile
  20. from ..common.error import Error
  21. from ..util.util import checkClusters, getConfig
  22. class Suite:
  23. def __init__(self, clusterName, dir_ec, dir_a, dir_ex, dir_r, logDir, dir_inc, args, isSetup=False, fileList = None):
  24. self.clusterName = clusterName
  25. self.targetName = clusterName
  26. if isSetup:
  27. self.targetName = 'setup_'+clusterName
  28. self.args=args
  29. self.suite = []
  30. self.dir_ec = dir_ec
  31. self.dir_a = dir_a
  32. self.dir_ex = dir_ex
  33. self.dir_r = dir_r
  34. self.logDir = logDir
  35. self.dir_inc = dir_inc
  36. self.exclude = []
  37. self.publish = []
  38. self.cleanUp()
  39. self.buildSuite(args, isSetup, fileList)
  40. if len(self.exclude):
  41. curTime = time.strftime("%y-%m-%d-%H-%M-%S")
  42. logName = self.targetName + "-exclusion." + curTime + ".log"
  43. self.logName = os.path.join(self.logDir, logName)
  44. args.exclusionFile=self.logName
  45. self.log = open(self.logName, "w");
  46. for item in self.exclude:
  47. self.log.write(item+"\n")
  48. self.log.close();
  49. def __del__(self):
  50. print "Suite destructor."
  51. pass
  52. def buildSuite(self, args, isSetup, fileList):
  53. if fileList == None:
  54. if not os.path.isdir(self.dir_ec):
  55. raise Error("2001", err="Not Found: %s" % self.dir_ec)
  56. allfiles = os.listdir(self.dir_ec)
  57. allfiles.sort()
  58. else:
  59. allfiles = fileList
  60. classIncluded='all'
  61. if 'runclass' in args:
  62. classIncluded=args.runclass[0].split(',')
  63. pass
  64. classExcluded='none'
  65. if 'excludeclass' in args:
  66. classExcluded = args.excludeclass[0].split(',')
  67. pass
  68. for file in allfiles:
  69. if file.endswith(".ecl"):
  70. ecl = os.path.join(self.dir_ec, file)
  71. eclfile = ECLFile(ecl, self.dir_a, self.dir_ex,
  72. self.dir_r, self.dir_inc, self.clusterName, args)
  73. if isSetup:
  74. skipResult = eclfile.testSkip('setup')
  75. else:
  76. skipResult = eclfile.testSkip(self.targetName)
  77. if not skipResult['skip']:
  78. exclude=False
  79. exclusionReason=''
  80. if isSetup:
  81. exclude = eclfile.testExclusion('setup')
  82. exclusionReason=' setup'
  83. elif ( 'all' not in classIncluded ) or ('none' not in classExcluded):
  84. included = True
  85. if 'all' not in classIncluded:
  86. included = eclfile.testInClass(classIncluded)
  87. excluded = False
  88. if 'none' not in classExcluded:
  89. excluded = eclfile.testInClass(classExcluded)
  90. exclude = (not included ) or excluded
  91. exclusionReason=' class member excluded'
  92. if not exclude:
  93. exclude = eclfile.testExclusion(self.targetName)
  94. exclusionReason=' ECL excluded'
  95. if not exclude:
  96. self.addFileToSuite(eclfile)
  97. else:
  98. self.exclude.append(format(file, "30")+exclusionReason)
  99. else:
  100. self.exclude.append(format(file, "30")+" skipped (reason:"+skipResult['reason']+")");
  101. if eclfile.testPublish():
  102. self.publish.append(eclfile.getBaseEcl())
  103. def addFileToSuite(self, eclfile):
  104. haveVersions = eclfile.testVesion()
  105. if haveVersions and not self.args.noversion:
  106. basename = eclfile.getEcl()
  107. files=[]
  108. versions = eclfile.getVersions()
  109. versionId = 1
  110. for version in versions:
  111. if 'no'+self.targetName in version:
  112. # Exclude it from this target
  113. pass
  114. else:
  115. # Remove exclusion key(s) from version string
  116. config = getConfig();
  117. for cluster in config.Clusters:
  118. version = version.replace(',no'+str(cluster), '')
  119. files.append({'basename':basename, 'version':version, 'id':versionId })
  120. versionId += 1
  121. pass
  122. pass
  123. # We have a list of different versions
  124. # generate ECLs to suite
  125. for file in files:
  126. generatedEclFile = ECLFile(basename, self.dir_a, self.dir_ex,
  127. self.dir_r, self.dir_inc, self.clusterName, self.args)
  128. generatedEclFile.setDParameters(file['version'])
  129. generatedEclFile.setVersionId(file['id'])
  130. # add newly generated ECL to suite
  131. self.suite.append(generatedEclFile)
  132. # Clean-up, the original eclfile object not necessary anymore
  133. eclfile.close()
  134. else:
  135. self.suite.append(eclfile)
  136. pass
  137. def testPublish(self, ecl):
  138. if ecl in self.publish:
  139. return True
  140. return False
  141. def getSuite(self):
  142. return self.suite
  143. def setStarTime(self, time):
  144. self.startTime = time
  145. def setEndTime(self, time):
  146. self.endTime=time
  147. def getElapsTime(self):
  148. return self.endTime-self.startTime
  149. def getSuiteName(self):
  150. return self.targetName
  151. def cleanUp(self):
  152. # If there are some temporary files left, then remove them
  153. for file in glob.glob(self.dir_ec+'/_temp*.ecl'):
  154. os.unlink(file)
  155. def close(self):
  156. for ecl in self.suite:
  157. ecl.close()
  158. self.cleanUp()