]> code.delx.au - offlineimap/commitdiff
Add a try: block to catch exceptions that occur before the main loop and to call...
authorDaniel Burrows <dburrows@debian.org>
Fri, 1 Dec 2006 10:59:22 +0000 (11:59 +0100)
committerDaniel Burrows <dburrows@debian.org>
Fri, 1 Dec 2006 10:59:22 +0000 (11:59 +0100)
I'm not sure if this is the "right" way to handle exceptions, but it does
correctly print the error message AFTER shutting down curses for me.

offlineimap/init.py

index 07809885c56a40e162d38ce7062fa946281b6e65..736f7850d18ef2529493be7ed06dc0ff4480f13a 100644 (file)
@@ -101,54 +101,58 @@ def startup(versionno):
 
     lock(config, ui)
 
-    if options.has_key('-l'):
-        sys.stderr = ui.logfile
-
-    activeaccounts = config.get("general", "accounts")
-    if options.has_key('-a'):
-        activeaccounts = options['-a']
-    activeaccounts = activeaccounts.replace(" ", "")
-    activeaccounts = activeaccounts.split(",")
-    allaccounts = accounts.AccountHashGenerator(config)
-
-    syncaccounts = {}
-    for account in activeaccounts:
-        if account not in allaccounts:
-            if len(allaccounts) == 0:
-                errormsg = 'The account "%s" does not exist because no accounts are defined!'%account
-            else:
-                errormsg = 'The account "%s" does not exist.  Valid accounts are:'%account
-                for name in allaccounts.keys():
-                    errormsg += '\n%s'%name
-            ui.terminate(1, errortitle = 'Unknown Account "%s"'%account, errormsg = errormsg)
-        syncaccounts[account] = allaccounts[account]
-
-    server = None
-    remoterepos = None
-    localrepos = None
-
-    if options.has_key('-1'):
-        threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
-    else:
-        threadutil.initInstanceLimit("ACCOUNTLIMIT",
-                                     config.getdefaultint("general", "maxsyncaccounts", 1))
-
-    for reposname in config.getsectionlist('Repository'):
-        for instancename in ["FOLDER_" + reposname,
-                             "MSGCOPY_" + reposname]:
-            if options.has_key('-1'):
-                threadutil.initInstanceLimit(instancename, 1)
-            else:
-                threadutil.initInstanceLimit(instancename,
-                                             config.getdefaultint('Repository ' + reposname, "maxconnections", 1))
-
-    threadutil.initexitnotify()
-    t = ExitNotifyThread(target=syncmaster.syncitall,
-                         name='Sync Runner',
-                         kwargs = {'accounts': syncaccounts,
-                                   'config': config})
-    t.setDaemon(1)
-    t.start()
+    try:
+        if options.has_key('-l'):
+            sys.stderr = ui.logfile
+
+        activeaccounts = config.get("general", "accounts")
+        if options.has_key('-a'):
+            activeaccounts = options['-a']
+        activeaccounts = activeaccounts.replace(" ", "")
+        activeaccounts = activeaccounts.split(",")
+        allaccounts = accounts.AccountHashGenerator(config)
+
+        syncaccounts = {}
+        for account in activeaccounts:
+            if account not in allaccounts:
+                if len(allaccounts) == 0:
+                    errormsg = 'The account "%s" does not exist because no accounts are defined!'%account
+                else:
+                    errormsg = 'The account "%s" does not exist.  Valid accounts are:'%account
+                    for name in allaccounts.keys():
+                        errormsg += '\n%s'%name
+                ui.terminate(1, errortitle = 'Unknown Account "%s"'%account, errormsg = errormsg)
+            syncaccounts[account] = allaccounts[account]
+
+        server = None
+        remoterepos = None
+        localrepos = None
+
+        if options.has_key('-1'):
+            threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
+        else:
+            threadutil.initInstanceLimit("ACCOUNTLIMIT",
+                                         config.getdefaultint("general", "maxsyncaccounts", 1))
+
+        for reposname in config.getsectionlist('Repository'):
+            for instancename in ["FOLDER_" + reposname,
+                                 "MSGCOPY_" + reposname]:
+                if options.has_key('-1'):
+                    threadutil.initInstanceLimit(instancename, 1)
+                else:
+                    threadutil.initInstanceLimit(instancename,
+                                                 config.getdefaultint('Repository ' + reposname, "maxconnections", 1))
+
+        threadutil.initexitnotify()
+        t = ExitNotifyThread(target=syncmaster.syncitall,
+                             name='Sync Runner',
+                             kwargs = {'accounts': syncaccounts,
+                                       'config': config})
+        t.setDaemon(1)
+        t.start()
+    except:
+        ui.mainException()
+
     try:
         threadutil.exitnotifymonitorloop(threadutil.threadexited)
     except SystemExit: