Package apama :: Module runner
[hide private]
[frames] | no frames]

Source Code for Module apama.runner

  1  #!/usr/bin/env python 
  2  # Copyright(c) 2007,2013 Progress Software Corporation (PSC).  All rights 
  3  # Copyright (c) 2013,2015-2016 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. 
  4  # Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG 
  5   
  6  import sys, stat, os, string, logging, socket, copy, random, types 
  7   
  8  from pysys import rootLogger 
  9  from pysys.constants import * 
 10  from pysys.exceptions import * 
 11  from pysys.baserunner import BaseRunner 
 12  from pysys.process.helper import ProcessWrapper 
 13  from apama.correlator import CorrelatorHelper 
 14   
 15   
16 -class ApamaRunner(BaseRunner):
17
18 - def __init__(self, record, purge, cycle, mode, threads, outsubdir, descriptors, xargs):
19 """Override the constructor of the base class to create required output directory. 20 21 """ 22 BaseRunner.__init__(self, record, purge, cycle, mode, threads, outsubdir, descriptors, xargs) 23 self.output = os.path.join(self.output, self.outsubdir) 24 self.__eplCoverageFiles = [] 25 26 27 def generateEplCoverage(): 28 cov = os.path.normpath(self.output+'/eplcoverage') 29 if not os.path.exists(cov): os.makedirs(cov) 30 self.purgeDirectory(cov) 31 log.info('Writing EPL code coverage output to: %s', cov) 32 with open(cov+'/coverage_files.txt', 'w') as f: 33 for l in self.__eplCoverageFiles: print >>f, l 34 arguments=[ 35 '--output', cov, 36 '--exclude', '**/Input/**.mon', # test files aren't interesting 37 38 # exclude all files from Apama monitor dir. 39 '--exclude', PROJECT.APAMA_HOME+'/monitors/**', 40 41 # not useful 42 '--exclude', '**/*.qry.mon', 43 '--exclude', '**/*.sdf.mon'] 44 if hasattr(self, 'eplcoverageinclude'): 45 arguments.extend(['--include', getattr(self, 'eplcoverageinclude', '')]) 46 if hasattr(self, 'eplcoverageexclude'): 47 arguments.extend(['--exclude', getattr(self, 'eplcoverageexclude', '')]) 48 if hasattr(self, 'eplcoveragesource'): 49 arguments.extend(['--source', getattr(self, 'eplcoveragesource', '')]) 50 if hasattr(self, 'eplcoveragetitle'): 51 arguments.extend(['--title', getattr(self, 'eplcoveragetitle', '')]) 52 arguments.append('@%s/coverage_files.txt'%cov) 53 self.startProcess(PROJECT.APAMA_HOME+'/bin/epl_coverage', 54 arguments=arguments, 55 state=FOREGROUND, 56 displayName='epl_coverage (with %d coverage files)'%(len(self.__eplCoverageFiles)), 57 stdout=cov+'/epl_coverage.out', 58 stderr=cov+'/epl_coverage.err', 59 )
60 if getattr(self, 'eplcoverage','').lower()=='true': 61 self.addCleanupFunction(generateEplCoverage)
62 63
64 - def isPurgableFile(self, path):
65 # override 66 return not path.endswith('.eplcoverage') and BaseRunner.isPurgableFile(self, path)
67 68
69 - def purgeDirectory(self, dir, delTop=False):
70 """Recursively purge a directory removing all files and sub-directories. 71 72 @param dir: The top level directory to be purged 73 @param delTop: Indicates if the top level directory should also be deleted 74 75 """ 76 try: 77 for file in os.listdir(dir): 78 path = os.path.join(dir, file) 79 if PLATFORM in ['sunos', 'linux']: 80 mode = os.lstat(path)[stat.ST_MODE] 81 else: 82 mode = os.stat(path)[stat.ST_MODE] 83 84 if stat.S_ISLNK(mode): 85 os.unlink(path) 86 if stat.S_ISREG(mode): 87 os.remove(path) 88 elif stat.S_ISDIR(mode): 89 self.purgeDirectory(path, delTop=True) 90 if delTop: os.rmdir(dir) 91 92 except OSError as ex: 93 log.warning("Caught OSError in purgeDirectory():") 94 log.warning(ex) 95 log.warning("Directory %s may not be completely purged" % dir)
96 97
98 - def testComplete(self, testObj, dir):
99 if getattr(self, 'eplcoverage','').lower()=='true' and os.path.exists(dir): 100 for p in os.listdir(dir): 101 if p.endswith('.eplcoverage'): 102 self.__eplCoverageFiles.append(dir+'/'+p) 103 BaseRunner.testComplete(self, testObj, dir)
104