From dc8f3c944dbfd9bad55c3789d81f2e0e60e6f225 Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Fri, 1 Dec 2006 11:59:22 +0100 Subject: [PATCH] Add a try: block to catch exceptions that occur before the main loop and to call ui.mainException(). 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 | 88 +++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/offlineimap/init.py b/offlineimap/init.py index 0780988..736f785 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -101,54 +101,58 @@ def startup(versionno): lock(config, ui) - if options.has_key('-l'): - sys.stderr = ui.logfile + 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) + 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] + 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 + server = None + remoterepos = None + localrepos = None - if options.has_key('-1'): - threadutil.initInstanceLimit("ACCOUNTLIMIT", 1) - else: - threadutil.initInstanceLimit("ACCOUNTLIMIT", - config.getdefaultint("general", "maxsyncaccounts", 1)) + 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)) + 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() - threadutil.initexitnotify() - t = ExitNotifyThread(target=syncmaster.syncitall, - name='Sync Runner', - kwargs = {'accounts': syncaccounts, - 'config': config}) - t.setDaemon(1) - t.start() try: threadutil.exitnotifymonitorloop(threadutil.threadexited) except SystemExit: