#!/usr/bin/python import cliapp import time class ListJobTimes(cliapp.Application): def process_input_line(self, filename, line): words = line.split() if len(words) < 6 or words[2] != 'INFO': pass elif words[3] == 'Starting' and words[4] == 'job': self.started = self.parse_time(words[0], words[1]) self.jobid = words[5] elif words[3] == 'Finished' and words[4] == 'job': ended = self.parse_time(words[0], words[1]) self.output.write('%.1f %s\n' % (ended - self.started, self.jobid)) self.started = None self.jobid = None def parse_time(self, dt, tm): t = time.strptime('%s %s' % (dt, tm), '%Y-%m-%d %H:%M:%S') return time.mktime(t) ListJobTimes().run()