]> snippets.scripts.mit.edu Git - Scripts/git/.git/blobdiff - barn-growl/barn-growl.py
Use pynotify instead of shelling out to notify-send.
[Scripts/git/.git] / barn-growl / barn-growl.py
index 8a46cb917fdbfd0f02f6469ade2e5d2188dea3c6..546cd694863cc1a776a9de49de8781ee2518ddc7 100755 (executable)
@@ -17,6 +17,10 @@ class Notifier(AbstractConsumer):
     def __init__(self, usegrowl, usenotify, useprint):
         self.usegrowl = usegrowl
         self.usenotify = usenotify
+        if usenotify:
+            import pynotify
+            pynotify.init("Zephyr")
+            self.pings = {}
         self.useprint = useprint
         return
     def feed(self, s):
@@ -48,8 +52,11 @@ class Notifier(AbstractConsumer):
                 g.stdin.write(message)
                 g.stdin.close()
             if self.usenotify:
-                notifysend = ['notify-send', header, message]
-                subprocess.call(notifysend)
+                import pynotify
+                if id in self.pings:
+                    self.pings[id].close()
+                self.pings[id] = pynotify.Notification(header, message)
+                self.pings[id].show()
     def close(self):
         return
 
@@ -86,6 +93,12 @@ def main(argv):
         return 1
     ssh = opts.ssh
 
+    if ssh is None:
+        retval = subprocess.call(['which', 'tzc'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        if retval:
+            print 'tzc not in path.  Please add -s username@machine to specify remote host.'
+            return 1
+
     if ssh is not None:
         command = "ssh -K %s 'tzc -si'" % ssh
     else:
@@ -96,13 +109,16 @@ def main(argv):
     flags = fcntl.fcntl(p, fcntl.F_GETFL)
     fcntl.fcntl(p, fcntl.F_SETFL, flags | os.O_NONBLOCK)
 
-    while 1:
-        [i,o,e] = select.select([p], [], [], 5)
-        if i: s = p.read(1024)
-        else: s = ''
+    try:
+        while 1:
+            [i,o,e] = select.select([p], [], [], 5)
+            if i: s = p.read(1024)
+            else: s = ''
 
-        if s != '':
-            r.feed(s)
+            if s != '':
+                r.feed(s)
+    except KeyboardInterrupt:
+        pass
     return 0
 
 if __name__ == "__main__":