Output sync timing

Modify the UI:acct and acctdone functions to keep tab of the time
inbetween. Put self.ui.acct() and acctdone() at the right places in
accounts.py so that the timing happens at the right places.

While modifying that loop, flatten the nested try: try: except: finally:
constructs, we require python 2.5 now which copes with that.

At the end of each account sync you will now see something like:
*** Finished account 'test' in 0:05

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-09-29 17:22:02 +02:00
parent ba396cf0ef
commit 3b647d65be
3 changed files with 38 additions and 32 deletions

View File

@ -18,6 +18,8 @@ Changes
* Indicate progress when copying many messages (slightly change log format) * Indicate progress when copying many messages (slightly change log format)
* Output how long an account sync took (min:sec).
Bug Fixes Bug Fixes
--------- ---------

View File

@ -1,5 +1,4 @@
# Copyright (C) 2003 John Goerzen # Copyright (C) 2003-2011 John Goerzen & contributors
# <jgoerzen@complete.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -196,7 +195,6 @@ class SyncableAccount(Account):
def syncrunner(self): def syncrunner(self):
self.ui.registerthread(self.name) self.ui.registerthread(self.name)
self.ui.acct(self.name)
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)
@ -208,32 +206,32 @@ class SyncableAccount(Account):
# Loop account sync if needed (bail out after 3 failures) # Loop account sync if needed (bail out after 3 failures)
looping = 3 looping = 3
while looping: while looping:
self.ui.acct(self)
try: try:
try: self.lock()
self.lock() self.sync()
self.sync() except (KeyboardInterrupt, SystemExit):
except (KeyboardInterrupt, SystemExit): raise
raise except OfflineImapError, e:
except OfflineImapError, e: # Stop looping and bubble up Exception if needed.
# Stop looping and bubble up Exception if needed. if e.severity >= OfflineImapError.ERROR.REPO:
if e.severity >= OfflineImapError.ERROR.REPO: if looping:
if looping: looping -= 1
looping -= 1 if e.severity >= OfflineImapError.ERROR.CRITICAL:
if e.severity >= OfflineImapError.ERROR.CRITICAL: raise
raise self.ui.error(e, exc_info()[2])
self.ui.error(e, exc_info()[2]) except Exception, e:
except Exception, e: self.ui.error(e, exc_info()[2], msg = "While attempting to sync"
self.ui.error(e, msg = "While attempting to sync " " account '%s'" % self)
"account %s:\n %s"% (self, traceback.format_exc())) else:
else: # after success sync, reset the looping counter to 3
# after success sync, reset the looping counter to 3 if self.refreshperiod:
if self.refreshperiod: looping = 3
looping = 3
finally: finally:
self.ui.acctdone(self)
self.unlock() self.unlock()
if looping and self.sleeper() >= 2: if looping and self.sleeper() >= 2:
looping = 0 looping = 0
self.ui.acctdone(self.name)
def getaccountmeta(self): def getaccountmeta(self):
return os.path.join(self.metadatadir, 'Account-' + self.name) return os.path.join(self.metadatadir, 'Account-' + self.name)

View File

@ -1,6 +1,5 @@
# UI base class # UI base class
# Copyright (C) 2002 John Goerzen # Copyright (C) 2002-2011 John Goerzen & contributors
# <jgoerzen@complete.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -48,6 +47,8 @@ class UIBase:
s.debugmsglen = 50 s.debugmsglen = 50
s.threadaccounts = {} s.threadaccounts = {}
"""dict linking active threads (k) to account names (v)""" """dict linking active threads (k) to account names (v)"""
s.acct_startimes = {}
"""linking active accounts with the time.time() when sync started"""
s.logfile = None s.logfile = None
s.exc_queue = Queue() s.exc_queue = Queue()
"""saves all occuring exceptions, so we can output them at the end""" """saves all occuring exceptions, so we can output them at the end"""
@ -238,13 +239,18 @@ class UIBase:
displaystr = '.' displaystr = '.'
s._msg("Establishing connection" + displaystr) s._msg("Establishing connection" + displaystr)
def acct(s, accountname): def acct(self, account):
if s.verbose >= 0: """Output that we start syncing an account (and start counting)"""
s._msg("***** Processing account %s" % accountname) self.acct_startimes[account] = time.time()
if self.verbose >= 0:
self._msg("*** Processing account %s" % account)
def acctdone(s, accountname): def acctdone(self, account):
if s.verbose >= 0: """Output that we finished syncing an account (in which time)"""
s._msg("***** Finished processing account " + accountname) sec = time.time() - self.acct_startimes[account]
del self.acct_startimes[account]
self._msg("*** Finished account '%s' in %d:%02d" %
(account, sec // 60, sec % 60))
def syncfolders(s, srcrepos, destrepos): def syncfolders(s, srcrepos, destrepos):
if s.verbose >= 0: if s.verbose >= 0: