[PATCH 4/5] Handle OfflineImapError of severity REPO and CRIT

Sebastian Spaeth Sebastian at SSpaeth.de
Wed May 4 15:45:27 BST 2011


By aborting the account syncing, the looping and logging an error
message. We will introduce a ui.error() rather than a ui.warn() function
which saves all Exceptions in a Queue and outputs them at the end of the
program.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/accounts.py |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
index a085288..f8e0d81 100644
--- a/offlineimap/accounts.py
+++ b/offlineimap/accounts.py
@@ -15,7 +15,7 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
-from offlineimap import threadutil, mbnames, CustomConfig
+from offlineimap import threadutil, mbnames, CustomConfig, OfflineImapError
 from offlineimap.repository import Repository
 from offlineimap.ui import getglobalui
 from offlineimap.threadutil import InstanceLimitedThread
@@ -184,21 +184,28 @@ class SyncableAccount(Account):
         self.localrepos  = Repository(self, 'local')
         self.statusrepos = Repository(self, 'status')
 
-        # Might need changes here to ensure that one account sync does
-        # not crash others...
         # Loop account synchronization if needed
-        looping = 1
+        looping = True
         while looping:
             try:
                 try:
                     self.sync(siglistener)
                 except (KeyboardInterrupt, SystemExit):
                     raise
+                except OfflineImapError, e:                    
+                    self.ui.warn(e.reason)
+                    #stop looping and bubble up Exception if needed
+                    if e.severity >= OfflineImapError.ERROR.REPO:
+                        looping = 0
+                        if e.severity > OfflineImapError.ERROR.REPO:
+                            raise
                 except:
-                    self.ui.warn("Error occured attempting to sync account " + self.name \
-                                 + ": " + traceback.format_exc())
+                    self.ui.warn("Error occured attempting to sync "\
+                                 "account '%s':\n"% (self, traceback.format_exc()))
             finally:
-                looping = self.refreshperiod and self.sleeper(siglistener) != 2
+                looping = looping and \
+                    self.refreshperiod and \
+                    self.sleeper(siglistener) != 2
                 self.ui.acctdone(self.name)
 
 
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list