--- a/borgend.py Mon Jan 22 18:16:51 2018 +0000 +++ b/borgend.py Mon Jan 22 18:56:43 2018 +0000 @@ -6,7 +6,6 @@ import logging.handlers import argparse import platform -import utils # # Branding @@ -30,6 +29,7 @@ logger=logging.getLogger(appname) logger.setLevel(loglevel) stderrlog=logging.StreamHandler() +stderrlog.setLevel(logging.WARNING) logger.addHandler(stderrlog) logger.propagate=True @@ -73,6 +73,7 @@ # Parse args. Let argparse handle errors/exit if there are any args= do_args() tray = None + backups=[] try: args=do_args() @@ -91,39 +92,41 @@ from queue import Queue import signal, os + scheduler = Scheduler() + scheduler.start() + backupconfigs=config.settings['backups'] - backups=[None]*len(backupconfigs); - scheduler = Scheduler() - - try: - scheduler.start() + for i in range(len(backupconfigs)): + logger.info('Setting up backup set %d' % i) + b=Backup(i, backupconfigs[i], scheduler) + backups.append(b) - for i in range(len(backupconfigs)): - logger.info('Setting up backup set %d' % i) - backups[i]=Backup(i, backupconfigs[i], scheduler) - backups[i].start() + for b in backups: + b.start() - if args.notray or platform.system()!='Darwin': - pass - else: - from ui import BorgendTray - tray=BorgendTray(backups); - tray.run() - finally: - for i in range(len(backups)): - if backups[i]: - backups[i].abort() - backups=[] + if args.notray or platform.system()!='Darwin': + # Wait for scheduler to finish + scheduler.join() + else: + # Start UI, and let it handle exit control + from ui import BorgendTray + tray=BorgendTray(backups); + tray.run() + except Exception as err: # TODO: Should write errors here to stderr; # perhaps add an extra stderr logger for error level messages - utils.log_exception(logger, err, detail='Exiting') + logger.exception("Exception fell through to outer level: exiting") + + finally: + for b in backups: + b.terminate() + if tray: tray.quit() else: logging.shutdown() - #sys.exit() # # This shit is fucked, disables ^C etc., and threading doesn't seem to help