]> snippets.scripts.mit.edu Git - Scripts/git/.git/blobdiff - barn-growl/barn-growl.py
kdo: Upstream krb5 now supports kswitch
[Scripts/git/.git] / barn-growl / barn-growl.py
index 8a46cb917fdbfd0f02f6469ade2e5d2188dea3c6..e36f7198b6de0ccae5874285779f3c649bd2d3e9 100755 (executable)
@@ -12,11 +12,17 @@ import select
 import sys
 from abstfilter import AbstractConsumer
 import optparse
+import time
 
 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.pynotify = pynotify
         self.useprint = useprint
         return
     def feed(self, s):
@@ -28,9 +34,10 @@ class Notifier(AbstractConsumer):
             zop = d['opcode'].lower()
             zsender = d['sender'].lower()
             zauth = d['auth'].lower() == 'yes'
-            ztime = ':'.join(d['time'].split(' ')[3].split(':')[0:2])
+            ztime = "%02d:%02d" % time.strptime(d['time'])[3:5]
             zmessage = d['message']
-            id = '%s/\n%s/\n%s\n %s' % (zclass, zinstance, zsender, ztime)
+            idtuple = (zclass, zinstance, zsender, ztime)
+            id = '%s/\n%s/\n%s\n %s' % idtuple
             if zop == 'ping':
                 header = '%s (%s)' % (id, zsender)
                 message = '...'
@@ -43,13 +50,20 @@ class Notifier(AbstractConsumer):
                 print (id, header)
                 print message
             if self.usegrowl:
-                growlnotify = ['growlnotify', '-a', 'MacZephyr', '-n', 'zephyr', '-d', id, '-t', header]
+                growlnotify = ['growlnotify', '-H', 'localhost', '-a', 'MacZephyr', '-n', 'zephyr', '-d', id, '-t', header]
                 g = subprocess.Popen(growlnotify, stdin=subprocess.PIPE)
                 g.stdin.write(message)
                 g.stdin.close()
             if self.usenotify:
-                notifysend = ['notify-send', header, message]
-                subprocess.call(notifysend)
+                if idtuple in self.pings:
+                    self.pings[idtuple].update(header, message)
+                    self.pings[idtuple].show()
+                else:
+                    n = self.pynotify.Notification(header, message)
+                    n.show()
+                    if zop == 'ping':
+                        self.pings[idtuple] = n
+                self.pings = dict(filter(lambda ((c, i, s, time), v): time == idtuple[3], self.pings.items()))
     def close(self):
         return
 
@@ -86,8 +100,14 @@ 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
+        command = "ssh -o GSSAPIAuthentication=yes -o GSSAPIDelegateCredentials=yes -o GSSAPIKeyExchange=yes %s 'tzc -si'" % ssh
     else:
         command = "tzc -si"
     p = os.popen(command)
@@ -96,13 +116,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__":