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 \
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
-
-