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 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 if self.mode == "batch": 25 if not os.path.exists(self.output): os.makedirs(self.output) 26 self.purgeDirectory(self.output)
27 28
29 - def setup(self):
30 """Override the setup method of the base class to start a correlator. 31 32 """ 33 if self.mode == "batch": 34 self.log.info("Requested mode for executing tests is batch mode") 35 self.correlator = CorrelatorHelper(self) 36 self.correlator.start(logfile='correlator.log')
37
38 - def purgeDirectory(self, dir, delTop=False):
39 """Recursively purge a directory removing all files and sub-directories. 40 41 @param dir: The top level directory to be purged 42 @param delTop: Indicates if the top level directory should also be deleted 43 44 """ 45 try: 46 for file in os.listdir(dir): 47 path = os.path.join(dir, file) 48 if PLATFORM in ['sunos', 'linux']: 49 mode = os.lstat(path)[stat.ST_MODE] 50 else: 51 mode = os.stat(path)[stat.ST_MODE] 52 53 if stat.S_ISLNK(mode): 54 os.unlink(path) 55 if stat.S_ISREG(mode): 56 os.remove(path) 57 elif stat.S_ISDIR(mode): 58 self.purgeDirectory(path, delTop=True) 59 if delTop: os.rmdir(dir) 60 61 except OSError as ex: 62 log.warning("Caught OSError in purgeDirectory():") 63 log.warning(ex) 64 log.warning("Directory %s may not be completely purged" % dir)
65