]> sipb.mit.edu Git - snippets/.git/commitdiff
Checks for tzc binary and punts if not found.
authorPeter Iannucci <iannucci@mit.edu>
Sun, 1 Mar 2009 02:40:17 +0000 (21:40 -0500)
committerPeter Iannucci <iannucci@mit.edu>
Sun, 1 Mar 2009 02:40:17 +0000 (21:40 -0500)
barn-growl/barn-growl.py

index 8a46cb917fdbfd0f02f6469ade2e5d2188dea3c6..6a4a7cbee9c26a61786d08fa27a8e3102e9a4386 100755 (executable)
@@ -86,6 +86,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 +102,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__":