borgend.py

Sun, 21 Jan 2018 17:45:55 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 21 Jan 2018 17:45:55 +0000
changeset 38
085a635f23f5
parent 36
1478f8722690
child 39
56af43e9c949
permissions
-rwxr-xr-x

Improved error indicators

#!/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_level=logging.INFO
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.setLevel(fifolog_level)
fifolog.setFormatter(logging.Formatter(fifolog_fmt))

if __name__=="__main__":

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

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