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