From cc5d8c83d8aeb8aed88b2055d0c9296e3870a560 Mon Sep 17 00:00:00 2001 From: Brandon King Date: Wed, 16 Jan 2008 02:13:59 +0000 Subject: [PATCH] Spoolwatch function for getting cycle number from Recipe*.xml file. * Work towards ticket:28. --- gaworkflow/automation/spoolwatcher.py | 41 ++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/gaworkflow/automation/spoolwatcher.py b/gaworkflow/automation/spoolwatcher.py index 308ea3e..d50eefb 100644 --- a/gaworkflow/automation/spoolwatcher.py +++ b/gaworkflow/automation/spoolwatcher.py @@ -4,6 +4,9 @@ import os import re import sys import time +import glob + + # this uses pyinotify import pyinotify @@ -11,6 +14,42 @@ from pyinotify import EventsCodes from benderjab import rpc + +s_cycles = re.compile('No. Cycles: (?P[0-9]+)') + +def get_cycles(run_dir="."): + """ + Find the number of cycles from the Recipe*.xml file found in run_dir. + """ + + file_path_list = glob.glob(os.path.join(run_dir, "Recipe*.xml")) + + # Error handling + if len(file_path_list) == 0: + msg = "Recipe xml file not found." + raise IOError, msg + + elif len(file_path_list) > 1: + msg = "%s Recipe files found, expected 1." % (len(file_path_list)) + raise ValueError, msg + + f = open(file_path_list[0], 'r') + + #Find the line of the file with the cycle number in it. + for line in f: + mo = s_cycles.search(line) + if mo: + break + + f.close() + + # Process the line with the cycle number in it. + cycle_num = int(mo.group('cycles')) + + return cycle_num + + + class WatcherEvents(object): # two events need to be tracked # one to send startCopy @@ -204,4 +243,4 @@ def main(args=None): if __name__ == "__main__": sys.exit(main(sys.argv[1:])) - \ No newline at end of file + -- 2.30.2