[project @ make a spoolwatcher script]
authorDiane Trout <diane@caltech.edu>
Thu, 9 Aug 2007 01:27:02 +0000 (01:27 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 9 Aug 2007 01:27:02 +0000 (01:27 +0000)
and put most of the configuration information in the script
(i really should load it from a config file at some point)
Also teach setup.py about said script

scripts/spoolwatcher [new file with mode: 0644]
setup.py
uashelper/spoolwatcher.py

diff --git a/scripts/spoolwatcher b/scripts/spoolwatcher
new file mode 100644 (file)
index 0000000..1e5d029
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+from uashelper.spoolwatcher import TreeWriteDoneNotifier
+
+if __name__ == "__main__":
+  copy_jid = "cellthumper@chaos.caltech.edu"
+  runner_jid = "diane@ghic.org"
+
+  watcher = TreeWriteDoneNotifier("/gec/jumpgate/ext0", copy_jid, runner_jid)
+  watcher.event_loop()
index 8761e55bd9701b3cb2d1218aeefcf113d64272e5..b21419383f5b75f33e46bfecc0e4cfad547322a2 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,6 @@ setup(
   description="some bots and other utilities to help deal with data from an illumina sequencer",
   author="Diane Trout",
   author_email="diane@caltech.edu",
-  packages="uashelper",
-  scripts=[],
+  packages=["uashelper"],
+  scripts=['scripts/spoolwatcher'],
 )
index b2520b206c563b0908e29c3dbe42e257656a2f43..cad3b2085a1f1fbe84389f5a6fb181b041c21543 100644 (file)
@@ -11,20 +11,18 @@ from pyinotify import EventsCodes
 
 from benderjab.xsend import send
 
-copy_jid = "cellthumper@chaos.caltech.edu"
-runner_jid = "diane@ghic.org"
-copy_jid = runner_jid
 class Handler(pyinotify.ProcessEvent):
-    def __init__(self, watchmanager):
+    def __init__(self, watchmanager, runner_jid):
       self.last_event_time = None
       self.watchmanager = watchmanager
+      self.runner_jid = runner_jid
 
     def process_IN_CREATE(self, event):
       self.last_event_time = time.time()
       msg = "Create: %s" %  os.path.join(event.path, event.name)
-      if event.name == "Run.completed":
+      if event.name.lower() == "run.completed":
         print "Run is done!"
-        send(runner_jid, "a run finished, launch it, and swap the drive")
+        send(self.runner_jid, "a run finished, launch it, and swap the drive")
       print msg
 
     def process_IN_DELETE(self, event):
@@ -45,19 +43,22 @@ class TreeWriteDoneNotifier:
   this'll hopefully send out a message saying hey look theres data available
   """
 
-  def __init__(self, watchdir, write_timeout=10, notify_timeout=5):
-     self.watchdirs = []
+  def __init__(self, watchdir, 
+                     copy_jid, runner_jid, 
+                     write_timeout=10, notify_timeout=5):
+     self.watchdir = watchdir
+     self.copy_jid = copy_jid
+     self.runner_jid = runner_jid
      self.write_timeout = write_timeout
      self.notify_timeout = int(notify_timeout * 1000)
 
      self.wm = pyinotify.WatchManager()
-     self.handler = Handler(self.wm)
+     self.handler = Handler(self.wm, self.runner_jid)
      self.notifier = pyinotify.Notifier(self.wm, self.handler)
      
-     self.add_watch(watchdir)
+     self.add_watch(self.watchdir)
 
   def add_watch(self, watchdir):
-     self.watchdirs.append(watchdir)
      print "Watching:", watchdir
      mask = EventsCodes.IN_CREATE | EventsCodes.IN_UNMOUNT
      # rec traverses the tree and adds all the directories that are there 
@@ -89,11 +90,5 @@ class TreeWriteDoneNotifier:
 
   def copying_paused(self):
     print "more than 10 seconds have elapsed"
-    send(copy_jid, "start copy")
-
-
-if __name__ == "__main__":
-  #watcher = TreeWriteDoneNotifier("/tmp")
-  watcher = TreeWriteDoneNotifier("/gec/jumpgate/ext0")
-  watcher.event_loop()
+    send(self.copy_jid, "start copy")