From fcc2cc6c85a345ac91547f9a2451ef679ef84b84 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Thu, 9 Aug 2007 01:27:02 +0000 Subject: [PATCH] [project @ make a spoolwatcher script] 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 | 10 ++++++++++ setup.py | 4 ++-- uashelper/spoolwatcher.py | 31 +++++++++++++------------------ 3 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 scripts/spoolwatcher diff --git a/scripts/spoolwatcher b/scripts/spoolwatcher new file mode 100644 index 0000000..1e5d029 --- /dev/null +++ b/scripts/spoolwatcher @@ -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() diff --git a/setup.py b/setup.py index 8761e55..b214193 100644 --- 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'], ) diff --git a/uashelper/spoolwatcher.py b/uashelper/spoolwatcher.py index b2520b2..cad3b20 100644 --- a/uashelper/spoolwatcher.py +++ b/uashelper/spoolwatcher.py @@ -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") -- 2.30.2