Improve TTY ui to not always prepend 'sync account foo'

This is very excessive and a bit annoying. Output that information
only if the next line concerns a different account/thread than the
previous one. This quiets down the UI quite a bit without losing
information.

While modifying this line, use the newer Thread.name and not the as
per python doc's old syntax getName()

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2010-12-05 15:35:02 +01:00 committed by Nicolas Sebrecht
parent f68b626cb4
commit 35dd236155

View File

@ -26,6 +26,7 @@ class TTYUI(UIBase):
UIBase.__init__(s, config, verbose)
s.iswaiting = 0
s.outputlock = Lock()
s._lastThreaddisplay = None
def isusable(s):
return sys.stdout.isatty() and sys.stdin.isatty()
@ -33,10 +34,16 @@ class TTYUI(UIBase):
def _display(s, msg):
s.outputlock.acquire()
try:
if (currentThread().getName() == 'MainThread'):
print msg
#if the next output comes from a different thread than our last one
#add the info.
#Most look like 'account sync foo' or 'Folder sync foo'.
threadname = currentThread().name
if (threadname == s._lastThreaddisplay):
print " %s" % msg
else:
print "%s:\n %s" % (currentThread().getName(), msg)
print "%s:\n %s" % (threadname, msg)
s._lastThreaddisplay = threadname
sys.stdout.flush()
finally:
s.outputlock.release()