From f4a32bafd64ee80050ee3aa85aab5a5d369693b6 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 3 Nov 2011 13:45:44 +0100 Subject: [PATCH] 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 --- offlineimap/accounts.py | 4 ++-- offlineimap/folder/Base.py | 2 +- offlineimap/ui/Curses.py | 11 +++++------ offlineimap/ui/Machine.py | 6 +++--- offlineimap/ui/UIBase.py | 8 +++++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 51a3ab9..bf3f327 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -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.\ diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index f8cea25..53bc71c 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -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 diff --git a/offlineimap/ui/Curses.py b/offlineimap/ui/Curses.py index bc63f7e..71ffe3a 100644 --- a/offlineimap/ui/Curses.py +++ b/offlineimap/ui/Curses.py @@ -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 diff --git a/offlineimap/ui/Machine.py b/offlineimap/ui/Machine.py index 334121d..868433a 100644 --- a/offlineimap/ui/Machine.py +++ b/offlineimap/ui/Machine.py @@ -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) diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py index 75cb313..0176422 100644 --- a/offlineimap/ui/UIBase.py +++ b/offlineimap/ui/UIBase.py @@ -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()