borgend.py

changeset 41
e2641cb9ca6d
parent 40
cfbeeec8cb82
child 43
8f3ac19f11b6
--- a/borgend.py	Sun Jan 21 21:32:48 2018 +0000
+++ b/borgend.py	Sun Jan 21 22:01:57 2018 +0000
@@ -1,6 +1,9 @@
 #!/usr/local/bin/python3
 
+import os
 import logging
+import logging.handlers
+import argparse
 from fifolog import FIFOHandler
 
 #
@@ -19,22 +22,48 @@
 fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s"
 
 #
-# Setup logger
+# Setup logger, needed by the config module to be loaded next
 #
 
 logger=logging.getLogger(appname)
 logger.setLevel(loglevel)
 logger.propagate=True
+
+#
+# Argument processing
+#
+
+import config
+
+def do_args():
+    parser=argparse.ArgumentParser(
+        description=appname_stylised + ': BorgBackup scheduler and tray icon.',
+        epilog='Configuration file location:\n\n    %s\n ' % config.cfgfile,
+        formatter_class=argparse.RawDescriptionHelpFormatter)
+
+    parser.add_argument(
+        '--no-tray',
+        dest='notray',
+        action='store_true',
+        help='Do not show the tray icon')
+
+    return parser.parse_args()
+
+#
+# Main routine
+#
+
+# First, setup our own logging handlers
 fifolog=FIFOHandler(fifolog_capacity)
 logger.addHandler(fifolog)
 fifolog.setFormatter(logging.Formatter(fifolog_fmt))
 
 if __name__=="__main__":
+    # Parse args. Let argparse handle errors/exit if there are any
+    args= do_args()
 
     try:
-        import logging.handlers
-        import os
-        import config
+        args=do_args()
 
         if not os.path.isdir(config.logs_dir):
             os.makedirs(config.logs_dir)
@@ -48,7 +77,6 @@
         from threading import Thread
         from backup import Backup
         from queue import Queue
-        from ui import BorgendTray
         import signal, os
 
         backupconfigs=config.settings['backups']
@@ -59,8 +87,13 @@
             backups[i]=Backup(i, backupconfigs[i])
             backups[i].schedule()
 
-        tray=BorgendTray(backups);
-        tray.run()
+        if args.notray:
+            pass
+        else:
+            from ui import BorgendTray
+            tray=BorgendTray(backups);
+            tray.run()
+
     except Exception as err:
         utils.log_exception(logger, err, detail='Exiting')
         logging.shutdown()

mercurial