borgend.py

Sun, 21 Jan 2018 21:32:48 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 21 Jan 2018 21:32:48 +0000
changeset 40
cfbeeec8cb82
parent 39
56af43e9c949
child 41
e2641cb9ca6d
permissions
-rwxr-xr-x

Improved exception reporting etc.

#!/usr/local/bin/python3

import logging
from fifolog import FIFOHandler

#
# Branding
#
appname="borgend"
appname_stylised="Borgend"

#
# Logging configuration
#

loglevel=logging.DEBUG
logfmt="%(asctime)s:%(levelname)s:%(name)s:%(message)s"
fifolog_capacity=1000
fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s"

#
# Setup logger
#

logger=logging.getLogger(appname)
logger.setLevel(loglevel)
logger.propagate=True
fifolog=FIFOHandler(fifolog_capacity)
logger.addHandler(fifolog)
fifolog.setFormatter(logging.Formatter(fifolog_fmt))

if __name__=="__main__":

    try:
        import logging.handlers
        import os
        import config

        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)

        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);

        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()
    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
    #

    # ui_thread=Thread(target=tray.run)
    # ui_thread.daemon=True
    # ui_thread.start()

    # def quit_signal_handler(signum, frame):
    #     print('Signal handler called with signal %s' % str(signum))
    #     ui_thread.terminate()
    #     os.exit()

    # signal.signal(signal.SIGTERM, quit_signal_handler)
    # signal.signal(signal.SIGINT, quit_signal_handler)

mercurial