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.
This commit is contained in:
parent
c7894a01f0
commit
dc8f3c944d
@ -101,54 +101,58 @@ def startup(versionno):
|
|||||||
|
|
||||||
lock(config, ui)
|
lock(config, ui)
|
||||||
|
|
||||||
if options.has_key('-l'):
|
try:
|
||||||
sys.stderr = ui.logfile
|
if options.has_key('-l'):
|
||||||
|
sys.stderr = ui.logfile
|
||||||
|
|
||||||
activeaccounts = config.get("general", "accounts")
|
activeaccounts = config.get("general", "accounts")
|
||||||
if options.has_key('-a'):
|
if options.has_key('-a'):
|
||||||
activeaccounts = options['-a']
|
activeaccounts = options['-a']
|
||||||
activeaccounts = activeaccounts.replace(" ", "")
|
activeaccounts = activeaccounts.replace(" ", "")
|
||||||
activeaccounts = activeaccounts.split(",")
|
activeaccounts = activeaccounts.split(",")
|
||||||
allaccounts = accounts.AccountHashGenerator(config)
|
allaccounts = accounts.AccountHashGenerator(config)
|
||||||
|
|
||||||
syncaccounts = {}
|
syncaccounts = {}
|
||||||
for account in activeaccounts:
|
for account in activeaccounts:
|
||||||
if account not in allaccounts:
|
if account not in allaccounts:
|
||||||
if len(allaccounts) == 0:
|
if len(allaccounts) == 0:
|
||||||
errormsg = 'The account "%s" does not exist because no accounts are defined!'%account
|
errormsg = 'The account "%s" does not exist because no accounts are defined!'%account
|
||||||
else:
|
else:
|
||||||
errormsg = 'The account "%s" does not exist. Valid accounts are:'%account
|
errormsg = 'The account "%s" does not exist. Valid accounts are:'%account
|
||||||
for name in allaccounts.keys():
|
for name in allaccounts.keys():
|
||||||
errormsg += '\n%s'%name
|
errormsg += '\n%s'%name
|
||||||
ui.terminate(1, errortitle = 'Unknown Account "%s"'%account, errormsg = errormsg)
|
ui.terminate(1, errortitle = 'Unknown Account "%s"'%account, errormsg = errormsg)
|
||||||
syncaccounts[account] = allaccounts[account]
|
syncaccounts[account] = allaccounts[account]
|
||||||
|
|
||||||
server = None
|
server = None
|
||||||
remoterepos = None
|
remoterepos = None
|
||||||
localrepos = None
|
localrepos = None
|
||||||
|
|
||||||
if options.has_key('-1'):
|
if options.has_key('-1'):
|
||||||
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
|
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
|
||||||
else:
|
else:
|
||||||
threadutil.initInstanceLimit("ACCOUNTLIMIT",
|
threadutil.initInstanceLimit("ACCOUNTLIMIT",
|
||||||
config.getdefaultint("general", "maxsyncaccounts", 1))
|
config.getdefaultint("general", "maxsyncaccounts", 1))
|
||||||
|
|
||||||
for reposname in config.getsectionlist('Repository'):
|
for reposname in config.getsectionlist('Repository'):
|
||||||
for instancename in ["FOLDER_" + reposname,
|
for instancename in ["FOLDER_" + reposname,
|
||||||
"MSGCOPY_" + reposname]:
|
"MSGCOPY_" + reposname]:
|
||||||
if options.has_key('-1'):
|
if options.has_key('-1'):
|
||||||
threadutil.initInstanceLimit(instancename, 1)
|
threadutil.initInstanceLimit(instancename, 1)
|
||||||
else:
|
else:
|
||||||
threadutil.initInstanceLimit(instancename,
|
threadutil.initInstanceLimit(instancename,
|
||||||
config.getdefaultint('Repository ' + reposname, "maxconnections", 1))
|
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:
|
try:
|
||||||
threadutil.exitnotifymonitorloop(threadutil.threadexited)
|
threadutil.exitnotifymonitorloop(threadutil.threadexited)
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
|
Loading…
Reference in New Issue
Block a user