def aggregate(self, takeFrom = "/var/log/hsn2", suffix = ".log"): ''' Collect chosen files into a separate directory. @param takeFrom: where files will be taken from @param suffix: The suffix of the files that are to be aggregated. Passing None means all files. ''' takeFrom = os.path.abspath(takeFrom) if takeFrom == self.putTo: logging.warning("takeFrom is the same as putTo '%s'. Aggregation skipped!" % takeFrom) else: logFiles = os.listdir(takeFrom) for logFile in logFiles: if suffix is None or os.path.splitext(logFile)[1] == suffix: shutil.move(os.path.join(takeFrom, logFile), os.path.join(self.putTo, logFile)) logging.info("Aggregated logs from %s to %s" % (takeFrom, self.putTo))
def __init__(self, jobId = 1): ''' Gathers all information about job from "hc j d". @param jobId: The id of the job about which the details will be gathered. ''' self.jobId = jobId lines = Console.call("hc j d %s" % self.jobId)[1].split('\n') for line in lines: if re.search(r'^\s', line) is None: continue elif re.search(r'task_count', line) is None: ret = re.search(r'\s*(\S+)\s*(\S.*)', line) #\s*([A-Z]+) if ret is None: logging.warning("job details fail: %s" % line) continue logging.debug("job details: %s = %s" % (ret.group(1), ret.group(2))) self.properties[ret.group(1)] = '%s' % ret.group(2) else: ret = re.search(r'\s*task_count_(\S+)\s*(\d+)\/(\d+)', line) if ret is None: logging.error("job details fail: %s" % line) continue logging.debug("job details: task_count_%s = %s/%s" % (ret.group(1), ret.group(2), ret.group(3))) self.properties[ret.group(1)] = (ret.group(2), ret.group(3))