Pass ui.registerthread an Account() and not a name as string

This way, we can use all the account functions such as set_abort_event()
from the ui if needed.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-11-03 13:45:44 +01:00
parent ab184d84e2
commit f4a32bafd6
5 changed files with 16 additions and 15 deletions

View File

@ -206,7 +206,7 @@ class SyncableAccount(Account):
pass #Failed to delete for some reason.
def syncrunner(self):
self.ui.registerthread(self.name)
self.ui.registerthread(self)
accountmetadata = self.getaccountmeta()
if not os.path.exists(accountmetadata):
os.mkdir(accountmetadata, 0700)
@ -338,7 +338,7 @@ def syncfolder(account, remotefolder, quick):
statusrepos = account.statusrepos
ui = getglobalui()
ui.registerthread(account.name)
ui.registerthread(account)
try:
# Load local folder.
localfolder = localrepos.\

View File

@ -254,7 +254,7 @@ class BaseFolder(object):
# self.getmessage(). So, don't call self.getmessage unless
# really needed.
if register: # output that we start a new thread
self.ui.registerthread(self.accountname)
self.ui.registerthread(self.repository.account)
try:
message = None

View File

@ -105,16 +105,16 @@ class CursesUtil:
class CursesAccountFrame:
"""Notable instance variables:
- accountname: String with associated account name
- account: corresponding Account()
- children
- ui
- key
- window: curses window associated with an account
"""
def __init__(self, ui, acc_name):
def __init__(self, ui, account):
self.children = []
self.acc_name = acc_name
self.account = account
self.ui = ui
self.window = None
"""Curses window associated with this acc"""
@ -128,7 +128,7 @@ class CursesAccountFrame:
secs tells us how long we are going to sleep."""
sleepstr = '%3d:%02d' % (secs // 60, secs % 60) if secs else 'active'
accstr = '%s: [%s] %12.12s: ' % (self.acc_num, sleepstr, self.acc_name)
accstr = '%s: [%s] %12.12s: ' % (self.acc_num, sleepstr, self.account)
self.ui.exec_locked(self.window.addstr, 0, 0, accstr)
self.location = len(accstr)
@ -491,8 +491,7 @@ class Blinkenlights(UIBase, CursesUtil):
try:
index = int(chr(key))
except ValueError:
# Key not a valid number: exit.
return
return # Key not a valid number: exit.
if index >= len(self.hotkeys):
# Not in our list of valid hotkeys.
return

View File

@ -42,9 +42,9 @@ class MachineUI(UIBase):
self.logger.warning("%s:%s:%s:%s" % (
'warn', '', currentThread().getName(), msg))
def registerthread(s, account):
UIBase.registerthread(s, account)
s._printData('registerthread', account)
def registerthread(self, account):
super(MachineUI, self).registerthread(self, account)
self._printData('registerthread', account)
def unregisterthread(s, thread):
UIBase.unregisterthread(s, thread)

View File

@ -160,12 +160,14 @@ class UIBase(object):
self.debug('thread', "Unregister thread '%s'" % thr.getName())
def getthreadaccount(self, thr = None):
"""Get name of account for a thread (current if None)"""
if not thr:
"""Get Account() for a thread (current if None)
If no account has been registered with this thread, return 'None'"""
if thr == None:
thr = threading.currentThread()
if thr in self.threadaccounts:
return self.threadaccounts[thr]
return '*Control' # unregistered thread is '*Control'
return None
def debug(self, debugtype, msg):
cur_thread = threading.currentThread()