gbp-create-remote-repo: don't expect a terminal
authorGuido Günther <agx@sigxcpu.org>
Sun, 18 Mar 2012 16:43:16 +0000 (17:43 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 18 Mar 2012 16:44:45 +0000 (17:44 +0100)
so you can do 'echo y | gbp-create-remote-repo'

gbp/scripts/create_remote_repo.py

index 7f2967b..6ecf12e 100644 (file)
@@ -117,12 +117,18 @@ def parse_remote(remote_url, name, pkg):
 
 def read_yn():
     fd = sys.stdin.fileno()
-    old_settings = termios.tcgetattr(fd)
     try:
-        tty.setraw(sys.stdin.fileno())
+        old_settings = termios.tcgetattr(fd)
+    except termios.error:
+        old_settings = None
+
+    try:
+        if old_settings:
+            tty.setraw(sys.stdin.fileno())
         ch = sys.stdin.read(1)
     finally:
-        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+        if old_settings:
+            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
 
     if ch in ( 'y', 'Y' ):
         return True