borgend.py

changeset 41
e2641cb9ca6d
parent 40
cfbeeec8cb82
child 43
8f3ac19f11b6
equal deleted inserted replaced
40:cfbeeec8cb82 41:e2641cb9ca6d
1 #!/usr/local/bin/python3 1 #!/usr/local/bin/python3
2 2
3 import os
3 import logging 4 import logging
5 import logging.handlers
6 import argparse
4 from fifolog import FIFOHandler 7 from fifolog import FIFOHandler
5 8
6 # 9 #
7 # Branding 10 # Branding
8 # 11 #
17 logfmt="%(asctime)s:%(levelname)s:%(name)s:%(message)s" 20 logfmt="%(asctime)s:%(levelname)s:%(name)s:%(message)s"
18 fifolog_capacity=1000 21 fifolog_capacity=1000
19 fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s" 22 fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s"
20 23
21 # 24 #
22 # Setup logger 25 # Setup logger, needed by the config module to be loaded next
23 # 26 #
24 27
25 logger=logging.getLogger(appname) 28 logger=logging.getLogger(appname)
26 logger.setLevel(loglevel) 29 logger.setLevel(loglevel)
27 logger.propagate=True 30 logger.propagate=True
31
32 #
33 # Argument processing
34 #
35
36 import config
37
38 def do_args():
39 parser=argparse.ArgumentParser(
40 description=appname_stylised + ': BorgBackup scheduler and tray icon.',
41 epilog='Configuration file location:\n\n %s\n ' % config.cfgfile,
42 formatter_class=argparse.RawDescriptionHelpFormatter)
43
44 parser.add_argument(
45 '--no-tray',
46 dest='notray',
47 action='store_true',
48 help='Do not show the tray icon')
49
50 return parser.parse_args()
51
52 #
53 # Main routine
54 #
55
56 # First, setup our own logging handlers
28 fifolog=FIFOHandler(fifolog_capacity) 57 fifolog=FIFOHandler(fifolog_capacity)
29 logger.addHandler(fifolog) 58 logger.addHandler(fifolog)
30 fifolog.setFormatter(logging.Formatter(fifolog_fmt)) 59 fifolog.setFormatter(logging.Formatter(fifolog_fmt))
31 60
32 if __name__=="__main__": 61 if __name__=="__main__":
62 # Parse args. Let argparse handle errors/exit if there are any
63 args= do_args()
33 64
34 try: 65 try:
35 import logging.handlers 66 args=do_args()
36 import os
37 import config
38 67
39 if not os.path.isdir(config.logs_dir): 68 if not os.path.isdir(config.logs_dir):
40 os.makedirs(config.logs_dir) 69 os.makedirs(config.logs_dir)
41 70
42 handler=logging.handlers.TimedRotatingFileHandler( 71 handler=logging.handlers.TimedRotatingFileHandler(
46 logger.addHandler(handler) 75 logger.addHandler(handler)
47 76
48 from threading import Thread 77 from threading import Thread
49 from backup import Backup 78 from backup import Backup
50 from queue import Queue 79 from queue import Queue
51 from ui import BorgendTray
52 import signal, os 80 import signal, os
53 81
54 backupconfigs=config.settings['backups'] 82 backupconfigs=config.settings['backups']
55 backups=[None]*len(backupconfigs); 83 backups=[None]*len(backupconfigs);
56 84
57 for i in range(len(backupconfigs)): 85 for i in range(len(backupconfigs)):
58 logger.info('Setting up backup set %d' % i) 86 logger.info('Setting up backup set %d' % i)
59 backups[i]=Backup(i, backupconfigs[i]) 87 backups[i]=Backup(i, backupconfigs[i])
60 backups[i].schedule() 88 backups[i].schedule()
61 89
62 tray=BorgendTray(backups); 90 if args.notray:
63 tray.run() 91 pass
92 else:
93 from ui import BorgendTray
94 tray=BorgendTray(backups);
95 tray.run()
96
64 except Exception as err: 97 except Exception as err:
65 utils.log_exception(logger, err, detail='Exiting') 98 utils.log_exception(logger, err, detail='Exiting')
66 logging.shutdown() 99 logging.shutdown()
67 100
68 # 101 #

mercurial