diff --git a/Changelog.draft.rst b/Changelog.draft.rst index ae84931..44048b9 100644 --- a/Changelog.draft.rst +++ b/Changelog.draft.rst @@ -18,6 +18,8 @@ Changes * Indicate progress when copying many messages (slightly change log format) +* Output how long an account sync took (min:sec). + Bug Fixes --------- diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index 6ab451f..2f674c9 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -1,5 +1,4 @@ -# Copyright (C) 2003 John Goerzen -# +# Copyright (C) 2003-2011 John Goerzen & contributors # # 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 @@ -196,7 +195,6 @@ class SyncableAccount(Account): def syncrunner(self): self.ui.registerthread(self.name) - self.ui.acct(self.name) accountmetadata = self.getaccountmeta() if not os.path.exists(accountmetadata): os.mkdir(accountmetadata, 0700) @@ -208,32 +206,32 @@ class SyncableAccount(Account): # Loop account sync if needed (bail out after 3 failures) looping = 3 while looping: + self.ui.acct(self) try: - try: - self.lock() - self.sync() - except (KeyboardInterrupt, SystemExit): - raise - except OfflineImapError, e: - # Stop looping and bubble up Exception if needed. - if e.severity >= OfflineImapError.ERROR.REPO: - if looping: - looping -= 1 - if e.severity >= OfflineImapError.ERROR.CRITICAL: - raise - self.ui.error(e, exc_info()[2]) - except Exception, e: - self.ui.error(e, msg = "While attempting to sync " - "account %s:\n %s"% (self, traceback.format_exc())) - else: - # after success sync, reset the looping counter to 3 - if self.refreshperiod: - looping = 3 + self.lock() + self.sync() + except (KeyboardInterrupt, SystemExit): + raise + except OfflineImapError, e: + # Stop looping and bubble up Exception if needed. + if e.severity >= OfflineImapError.ERROR.REPO: + if looping: + looping -= 1 + if e.severity >= OfflineImapError.ERROR.CRITICAL: + raise + self.ui.error(e, exc_info()[2]) + except Exception, e: + self.ui.error(e, exc_info()[2], msg = "While attempting to sync" + " account '%s'" % self) + else: + # after success sync, reset the looping counter to 3 + if self.refreshperiod: + looping = 3 finally: + self.ui.acctdone(self) self.unlock() if looping and self.sleeper() >= 2: looping = 0 - self.ui.acctdone(self.name) def getaccountmeta(self): return os.path.join(self.metadatadir, 'Account-' + self.name) diff --git a/offlineimap/ui/UIBase.py b/offlineimap/ui/UIBase.py index 587b055..dc95c30 100644 --- a/offlineimap/ui/UIBase.py +++ b/offlineimap/ui/UIBase.py @@ -1,6 +1,5 @@ # UI base class -# Copyright (C) 2002 John Goerzen -# +# Copyright (C) 2002-2011 John Goerzen & contributors # # 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 @@ -48,6 +47,8 @@ class UIBase: s.debugmsglen = 50 s.threadaccounts = {} """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.exc_queue = Queue() """saves all occuring exceptions, so we can output them at the end""" @@ -238,13 +239,18 @@ class UIBase: displaystr = '.' s._msg("Establishing connection" + displaystr) - def acct(s, accountname): - if s.verbose >= 0: - s._msg("***** Processing account %s" % accountname) + def acct(self, account): + """Output that we start syncing an account (and start counting)""" + self.acct_startimes[account] = time.time() + if self.verbose >= 0: + self._msg("*** Processing account %s" % account) - def acctdone(s, accountname): - if s.verbose >= 0: - s._msg("***** Finished processing account " + accountname) + def acctdone(self, account): + """Output that we finished syncing an account (in which time)""" + 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): if s.verbose >= 0: