Sun, 21 Jan 2018 21:32:48 +0000
Improved exception reporting etc.
borgend.py | file | annotate | diff | comparison | revisions | |
ui.py | file | annotate | diff | comparison | revisions | |
utils.py | file | annotate | diff | comparison | revisions |
--- a/borgend.py Sun Jan 21 18:32:14 2018 +0000 +++ b/borgend.py Sun Jan 21 21:32:48 2018 +0000 @@ -31,35 +31,39 @@ if __name__=="__main__": - import logging.handlers - import os - import config + try: + import logging.handlers + import os + import config - if not os.path.isdir(config.logs_dir): - os.makedirs(config.logs_dir) + if not os.path.isdir(config.logs_dir): + os.makedirs(config.logs_dir) - handler=logging.handlers.TimedRotatingFileHandler( - os.path.join(config.logs_dir, appname+'.log'), - when='D', interval=1) - handler.setFormatter(logging.Formatter(logfmt)) - logger.addHandler(handler) + handler=logging.handlers.TimedRotatingFileHandler( + os.path.join(config.logs_dir, appname+'.log'), + when='D', interval=1) + handler.setFormatter(logging.Formatter(logfmt)) + logger.addHandler(handler) - from threading import Thread - from backup import Backup - from queue import Queue - from ui import BorgendTray - import signal, os + from threading import Thread + from backup import Backup + from queue import Queue + from ui import BorgendTray + import signal, os + + backupconfigs=config.settings['backups'] + backups=[None]*len(backupconfigs); - backupconfigs=config.settings['backups'] - backups=[None]*len(backupconfigs); + for i in range(len(backupconfigs)): + logger.info('Setting up backup set %d' % i) + backups[i]=Backup(i, backupconfigs[i]) + backups[i].schedule() - for i in range(len(backupconfigs)): - logger.info('Setting up backup set %d' % i) - backups[i]=Backup(i, backupconfigs[i]) - backups[i].schedule() - - tray=BorgendTray(backups); - tray.run() + tray=BorgendTray(backups); + tray.run() + except Exception as err: + utils.log_exception(logger, err, detail='Exiting') + logging.shutdown() # # This shit is fucked, disables ^C etc., and threading doesn't seem to help
--- a/ui.py Sun Jan 21 18:32:14 2018 +0000 +++ b/ui.py Sun Jan 21 21:32:48 2018 +0000 @@ -1,5 +1,5 @@ # -# MacOS UI +# Borgend MacOS UI # import rumps @@ -7,6 +7,7 @@ import datetime import logging import borgend +import utils from threading import Lock, Timer from config import settings import objc @@ -42,7 +43,8 @@ rumps.notification(title, subtitle, message, data=d) except Exception as err: - logger.debug('Unable to display notificaton:%s:%s',err.__class__.__name__, str(err)) + utils.log_exception(logger, err, + detail='Unable to display notification') # Based on code snatched from # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 @@ -211,8 +213,7 @@ try: b.create(None) except Exception as err: - logger.debug("Opening notification for exception %s '%s'", - err.__class__.__name__, str(err)) + utils.log_exception(logger, err) notification_workaround(borgend.appname_stylised, err.__class__.__name__, str(err)) @@ -233,5 +234,5 @@ # Does not return until closed self.logwindow=None except Exception as err: - logger.critical('%s:%s', err.__class__.__name__, str(err)) + utils.log_exception(logger, err)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils.py Sun Jan 21 21:32:48 2018 +0000 @@ -0,0 +1,10 @@ +# +# Utility functions for Borgend +# + +def log_exception(logger, err, detail=None): + err_type=err.__class__.__name__ + if detail: + logger.critical('%s:%s "%s"', str(detail), err_type, str(err)) + else: + logger.critical('%s "%s"', err_type, str(err))