inotify doesn't work on Mac so we made it optional (on the existance of the package...
authorUnknown Author <unknown>
Tue, 5 Aug 2008 22:29:49 +0000 (22:29 +0000)
committerUnknown Author <unknown>
Tue, 5 Aug 2008 22:29:49 +0000 (22:29 +0000)
htswdataprod/htswdataprod/configure_run.py

index 0ad9b013f8a77cfdf2622307a630950ec192e432..42b504288142d1a1988415a80caee415e2f5ff97 100644 (file)
@@ -10,8 +10,14 @@ from htswdataprod.retrieve_config import FlowCellNotFound, WebError404
 from htswdataprod.genome_mapper import DuplicateGenome, getAvailableGenomes, constructMapperDict
 from htswdataprod.run_status import GARunStatus
 
-from pyinotify import WatchManager, ThreadedNotifier
-from pyinotify import EventsCodes, ProcessEvent
+try:
+  from pyinotify import WatchManager, ThreadedNotifier
+  from pyinotify import EventsCodes, ProcessEvent
+  USE_PYINOTIFY = True
+except: 
+  print "can't use pyinotify package"
+  USE_PYINOTIFY = False
+  
 
 class ConfigInfo:
   
@@ -56,53 +62,54 @@ s_gerald_all = re.compile('Firecrest[0-9\._\-A-Za-z]+/Bustard[0-9\._\-A-Za-z]+/G
 s_bustard_all = re.compile('Firecrest[0-9\._\-A-Za-z]+/Bustard[0-9\._\-A-Za-z]+/')
 s_firecrest_all = re.compile('Firecrest[0-9\._\-A-Za-z]+/')
 
-class RunEvent(ProcessEvent):
-
-  def __init__(self, conf_info):
-
-    self.run_status_dict = {'firecrest': False,
-                            'bustard': False,
-                            'gerald': False}
-
-    self._ci = conf_info
-
-    ProcessEvent.__init__(self)
-    
-
-  def process_IN_CREATE(self, event):
-    fullpath = os.path.join(event.path, event.name)
-    if s_finished.search(fullpath):
-      logging.info("File Found: %s" % (fullpath))
-
-      if s_firecrest_finished.search(fullpath):
-        self.run_status_dict['firecrest'] = True
-        self._ci.status.updateFirecrest(event.name)
-      elif s_bustard_finished.search(fullpath):
-        self.run_status_dict['bustard'] = True
-        self._ci.status.updateBustard(event.name)
-      elif s_gerald_finished.search(fullpath):
-        self.run_status_dict['gerald'] = True
-        self._ci.status.updateGerald(event.name)
-
-    #WARNING: The following order is important!!
-    # Firecrest regex will catch all gerald, bustard, and firecrest
-    # Bustard regex will catch all gerald and bustard
-    # Gerald regex will catch all gerald
-    # So, order needs to be Gerald, Bustard, Firecrest, or this
-    #  won't work properly.
-    elif s_gerald_all.search(fullpath):
-      self._ci.status.updateGerald(event.name)
-    elif s_bustard_all.search(fullpath):
-      self._ci.status.updateBustard(event.name)
-    elif s_firecrest_all.search(fullpath):
-      self._ci.status.updateFirecrest(event.name)
+if USE_PYINOTIFY:
+  class RunEvent(ProcessEvent):
+  
+    def __init__(self, conf_info):
+  
+      self.run_status_dict = {'firecrest': False,
+                              'bustard': False,
+                              'gerald': False}
+  
+      self._ci = conf_info
+  
+      ProcessEvent.__init__(self)
       
-    #print "Create: %s" % (os.path.join(event.path, event.name))
-
-  def process_IN_DELETE(self, event):
-    #print "Remove %s" % (os.path.join(event.path, event.name))
-    pass
-
+  
+    def process_IN_CREATE(self, event):
+      fullpath = os.path.join(event.path, event.name)
+      if s_finished.search(fullpath):
+        logging.info("File Found: %s" % (fullpath))
+  
+        if s_firecrest_finished.search(fullpath):
+          self.run_status_dict['firecrest'] = True
+          self._ci.status.updateFirecrest(event.name)
+        elif s_bustard_finished.search(fullpath):
+          self.run_status_dict['bustard'] = True
+          self._ci.status.updateBustard(event.name)
+        elif s_gerald_finished.search(fullpath):
+          self.run_status_dict['gerald'] = True
+          self._ci.status.updateGerald(event.name)
+  
+      #WARNING: The following order is important!!
+      # Firecrest regex will catch all gerald, bustard, and firecrest
+      # Bustard regex will catch all gerald and bustard
+      # Gerald regex will catch all gerald
+      # So, order needs to be Gerald, Bustard, Firecrest, or this
+      #  won't work properly.
+      elif s_gerald_all.search(fullpath):
+        self._ci.status.updateGerald(event.name)
+      elif s_bustard_all.search(fullpath):
+        self._ci.status.updateBustard(event.name)
+      elif s_firecrest_all.search(fullpath):
+        self._ci.status.updateFirecrest(event.name)
+        
+      #print "Create: %s" % (os.path.join(event.path, event.name))
+  
+    def process_IN_DELETE(self, event):
+      #print "Remove %s" % (os.path.join(event.path, event.name))
+      pass
+  
 
 
 
@@ -539,13 +546,14 @@ def run_pipeline(conf_info):
   # Create status object
   conf_info.createStatusObject()
 
-  # Monitor file creation
-  wm = WatchManager()
-  mask = EventsCodes.IN_DELETE | EventsCodes.IN_CREATE
-  event = RunEvent(conf_info)
-  notifier = ThreadedNotifier(wm, event)
-  notifier.start()
-  wdd = wm.add_watch(conf_info.run_path, mask, rec=True)
+  if USE_PYINOTIFY:
+    # Monitor file creation
+    wm = WatchManager()
+    mask = EventsCodes.IN_DELETE | EventsCodes.IN_CREATE
+    event = RunEvent(conf_info)
+    notifier = ThreadedNotifier(wm, event)
+    notifier.start()
+    wdd = wm.add_watch(conf_info.run_path, mask, rec=True)
 
   # Log pipeline starting
   logging.info('STARTING PIPELINE @ %s' % (time.ctime()))