Spoolwatch function for getting cycle number from Recipe*.xml file.
authorBrandon King <kingb@caltech.edu>
Wed, 16 Jan 2008 02:13:59 +0000 (02:13 +0000)
committerBrandon King <kingb@caltech.edu>
Wed, 16 Jan 2008 02:13:59 +0000 (02:13 +0000)
 * Work towards ticket:28.

gaworkflow/automation/spoolwatcher.py

index 308ea3e07c39ea017443c970d368d67bd4ea57c9..d50eefbd6ea9b3cf11b2575ce7181d642b282b8b 100644 (file)
@@ -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<cycles>[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
+