]> code.delx.au - offlineimap/blobdiff - offlineimap/head/offlineimap/ui/TTY.py
/offlineimap/head: changeset 367
[offlineimap] / offlineimap / head / offlineimap / ui / TTY.py
index a07961c3cc02ebcc4e45788f17b44254e38eac0a..a64e388a312e8499d98db539228a2bdc1b0506a7 100644 (file)
@@ -22,28 +22,35 @@ import select, sys
 from threading import *
 
 class TTYUI(UIBase):
-    def __init__(s, verbose = 0):
-        s.verbose = verbose
+    def __init__(s, config, verbose = 0):
+        UIBase.__init__(s, config, verbose)
         s.iswaiting = 0
+        s.outputlock = Lock()
+
+    def isusable(s):
+        return sys.stdout.isatty() and sys.stdin.isatty()
         
     def _msg(s, msg):
-        if (currentThread().getName() == 'MainThread'):
-            print msg
-        else:
-            print "%s:\n   %s" % (currentThread().getName(), msg)
-        sys.stdout.flush()
-
-    def getpass(s, accountname, config):
-        return getpass("%s: Enter password for %s on %s: " %
-                       (accountname, config.get(accountname, "remoteuser"),
-                        config.get(accountname, "remotehost")))
+        s.outputlock.acquire()
+        try:
+            if (currentThread().getName() == 'MainThread'):
+                print msg
+            else:
+                print "%s:\n   %s" % (currentThread().getName(), msg)
+            sys.stdout.flush()
+        finally:
+            s.outputlock.release()
 
-    def sleep(s, sleepsecs):
-        s.iswaiting = 1
+    def getpass(s, accountname, config, errmsg = None):
+        if errmsg:
+            s._msg("%s: %s" % (accountname, errmsg))
+        s.outputlock.acquire()
         try:
-            UIBase.sleep(s, sleepsecs)
+            return getpass("%s: Enter password for %s on %s: " %
+                           (accountname, config.get(accountname, "remoteuser"),
+                            config.get(accountname, "remotehost")))
         finally:
-            s.iswaiting = 0
+            s.outputlock.release()
 
     def mainException(s):
         if isinstance(sys.exc_info()[1], KeyboardInterrupt) and \
@@ -53,18 +60,3 @@ class TTYUI(UIBase):
         else:
             UIBase.mainException(s)
 
-    def sleeping(s, sleepsecs, remainingsecs):
-        if remainingsecs > 0:
-            sys.stdout.write("Next sync in %d:%02d (press Enter to sync now, Ctrl-C to abort)   \r" % \
-                             (remainingsecs / 60, remainingsecs % 60))
-            sys.stdout.flush()
-        else:
-            sys.stdout.write("Wait done, proceeding with sync....                                \n")
-
-        if sleepsecs > 0:
-            if len(select.select([sys.stdin], [], [], sleepsecs)[0]):
-                sys.stdin.readline()
-                return 1
-        return 0
-            
-