borgend.py

changeset 40
cfbeeec8cb82
parent 39
56af43e9c949
child 41
e2641cb9ca6d
--- 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

mercurial