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:
parent
ab184d84e2
commit
f4a32bafd6
@ -206,7 +206,7 @@ class SyncableAccount(Account):
|
|||||||
pass #Failed to delete for some reason.
|
pass #Failed to delete for some reason.
|
||||||
|
|
||||||
def syncrunner(self):
|
def syncrunner(self):
|
||||||
self.ui.registerthread(self.name)
|
self.ui.registerthread(self)
|
||||||
accountmetadata = self.getaccountmeta()
|
accountmetadata = self.getaccountmeta()
|
||||||
if not os.path.exists(accountmetadata):
|
if not os.path.exists(accountmetadata):
|
||||||
os.mkdir(accountmetadata, 0700)
|
os.mkdir(accountmetadata, 0700)
|
||||||
@ -338,7 +338,7 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
statusrepos = account.statusrepos
|
statusrepos = account.statusrepos
|
||||||
|
|
||||||
ui = getglobalui()
|
ui = getglobalui()
|
||||||
ui.registerthread(account.name)
|
ui.registerthread(account)
|
||||||
try:
|
try:
|
||||||
# Load local folder.
|
# Load local folder.
|
||||||
localfolder = localrepos.\
|
localfolder = localrepos.\
|
||||||
|
@ -254,7 +254,7 @@ class BaseFolder(object):
|
|||||||
# self.getmessage(). So, don't call self.getmessage unless
|
# self.getmessage(). So, don't call self.getmessage unless
|
||||||
# really needed.
|
# really needed.
|
||||||
if register: # output that we start a new thread
|
if register: # output that we start a new thread
|
||||||
self.ui.registerthread(self.accountname)
|
self.ui.registerthread(self.repository.account)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = None
|
message = None
|
||||||
|
@ -105,16 +105,16 @@ class CursesUtil:
|
|||||||
class CursesAccountFrame:
|
class CursesAccountFrame:
|
||||||
"""Notable instance variables:
|
"""Notable instance variables:
|
||||||
|
|
||||||
- accountname: String with associated account name
|
- account: corresponding Account()
|
||||||
- children
|
- children
|
||||||
- ui
|
- ui
|
||||||
- key
|
- key
|
||||||
- window: curses window associated with an account
|
- window: curses window associated with an account
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, ui, acc_name):
|
def __init__(self, ui, account):
|
||||||
self.children = []
|
self.children = []
|
||||||
self.acc_name = acc_name
|
self.account = account
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.window = None
|
self.window = None
|
||||||
"""Curses window associated with this acc"""
|
"""Curses window associated with this acc"""
|
||||||
@ -128,7 +128,7 @@ class CursesAccountFrame:
|
|||||||
|
|
||||||
secs tells us how long we are going to sleep."""
|
secs tells us how long we are going to sleep."""
|
||||||
sleepstr = '%3d:%02d' % (secs // 60, secs % 60) if secs else 'active'
|
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.ui.exec_locked(self.window.addstr, 0, 0, accstr)
|
||||||
self.location = len(accstr)
|
self.location = len(accstr)
|
||||||
@ -491,8 +491,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
|||||||
try:
|
try:
|
||||||
index = int(chr(key))
|
index = int(chr(key))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Key not a valid number: exit.
|
return # Key not a valid number: exit.
|
||||||
return
|
|
||||||
if index >= len(self.hotkeys):
|
if index >= len(self.hotkeys):
|
||||||
# Not in our list of valid hotkeys.
|
# Not in our list of valid hotkeys.
|
||||||
return
|
return
|
||||||
|
@ -42,9 +42,9 @@ class MachineUI(UIBase):
|
|||||||
self.logger.warning("%s:%s:%s:%s" % (
|
self.logger.warning("%s:%s:%s:%s" % (
|
||||||
'warn', '', currentThread().getName(), msg))
|
'warn', '', currentThread().getName(), msg))
|
||||||
|
|
||||||
def registerthread(s, account):
|
def registerthread(self, account):
|
||||||
UIBase.registerthread(s, account)
|
super(MachineUI, self).registerthread(self, account)
|
||||||
s._printData('registerthread', account)
|
self._printData('registerthread', account)
|
||||||
|
|
||||||
def unregisterthread(s, thread):
|
def unregisterthread(s, thread):
|
||||||
UIBase.unregisterthread(s, thread)
|
UIBase.unregisterthread(s, thread)
|
||||||
|
@ -160,12 +160,14 @@ class UIBase(object):
|
|||||||
self.debug('thread', "Unregister thread '%s'" % thr.getName())
|
self.debug('thread', "Unregister thread '%s'" % thr.getName())
|
||||||
|
|
||||||
def getthreadaccount(self, thr = None):
|
def getthreadaccount(self, thr = None):
|
||||||
"""Get name of account for a thread (current if None)"""
|
"""Get Account() for a thread (current if None)
|
||||||
if not thr:
|
|
||||||
|
If no account has been registered with this thread, return 'None'"""
|
||||||
|
if thr == None:
|
||||||
thr = threading.currentThread()
|
thr = threading.currentThread()
|
||||||
if thr in self.threadaccounts:
|
if thr in self.threadaccounts:
|
||||||
return self.threadaccounts[thr]
|
return self.threadaccounts[thr]
|
||||||
return '*Control' # unregistered thread is '*Control'
|
return None
|
||||||
|
|
||||||
def debug(self, debugtype, msg):
|
def debug(self, debugtype, msg):
|
||||||
cur_thread = threading.currentThread()
|
cur_thread = threading.currentThread()
|
||||||
|
Loading…
Reference in New Issue
Block a user