borgend.py

changeset 50
2d8947351727
parent 49
db33dfa64ad6
child 52
aef860e99323
equal deleted inserted replaced
49:db33dfa64ad6 50:2d8947351727
4 import sys 4 import sys
5 import logging 5 import logging
6 import logging.handlers 6 import logging.handlers
7 import argparse 7 import argparse
8 import platform 8 import platform
9 import utils
10 9
11 # 10 #
12 # Branding 11 # Branding
13 # 12 #
14 appname="borgend" 13 appname="borgend"
28 # 27 #
29 28
30 logger=logging.getLogger(appname) 29 logger=logging.getLogger(appname)
31 logger.setLevel(loglevel) 30 logger.setLevel(loglevel)
32 stderrlog=logging.StreamHandler() 31 stderrlog=logging.StreamHandler()
32 stderrlog.setLevel(logging.WARNING)
33 logger.addHandler(stderrlog) 33 logger.addHandler(stderrlog)
34 logger.propagate=True 34 logger.propagate=True
35 35
36 # 36 #
37 # Import our own modules. This needs to be done here 37 # Import our own modules. This needs to be done here
71 71
72 if __name__=="__main__": 72 if __name__=="__main__":
73 # Parse args. Let argparse handle errors/exit if there are any 73 # Parse args. Let argparse handle errors/exit if there are any
74 args= do_args() 74 args= do_args()
75 tray = None 75 tray = None
76 backups=[]
76 77
77 try: 78 try:
78 args=do_args() 79 args=do_args()
79 80
80 if not os.path.isdir(config.logs_dir): 81 if not os.path.isdir(config.logs_dir):
89 from threading import Thread 90 from threading import Thread
90 from backup import Backup 91 from backup import Backup
91 from queue import Queue 92 from queue import Queue
92 import signal, os 93 import signal, os
93 94
95 scheduler = Scheduler()
96 scheduler.start()
97
94 backupconfigs=config.settings['backups'] 98 backupconfigs=config.settings['backups']
95 backups=[None]*len(backupconfigs);
96 99
97 scheduler = Scheduler() 100 for i in range(len(backupconfigs)):
101 logger.info('Setting up backup set %d' % i)
102 b=Backup(i, backupconfigs[i], scheduler)
103 backups.append(b)
98 104
99 try: 105 for b in backups:
100 scheduler.start() 106 b.start()
101 107
102 for i in range(len(backupconfigs)): 108 if args.notray or platform.system()!='Darwin':
103 logger.info('Setting up backup set %d' % i) 109 # Wait for scheduler to finish
104 backups[i]=Backup(i, backupconfigs[i], scheduler) 110 scheduler.join()
105 backups[i].start() 111 else:
112 # Start UI, and let it handle exit control
113 from ui import BorgendTray
114 tray=BorgendTray(backups);
115 tray.run()
106 116
107 if args.notray or platform.system()!='Darwin':
108 pass
109 else:
110 from ui import BorgendTray
111 tray=BorgendTray(backups);
112 tray.run()
113 finally:
114 for i in range(len(backups)):
115 if backups[i]:
116 backups[i].abort()
117 backups=[]
118 except Exception as err: 117 except Exception as err:
119 # TODO: Should write errors here to stderr; 118 # TODO: Should write errors here to stderr;
120 # perhaps add an extra stderr logger for error level messages 119 # perhaps add an extra stderr logger for error level messages
121 utils.log_exception(logger, err, detail='Exiting') 120 logger.exception("Exception fell through to outer level: exiting")
121
122 finally:
123 for b in backups:
124 b.terminate()
125
122 if tray: 126 if tray:
123 tray.quit() 127 tray.quit()
124 else: 128 else:
125 logging.shutdown() 129 logging.shutdown()
126 #sys.exit()
127 130
128 # 131 #
129 # This shit is fucked, disables ^C etc., and threading doesn't seem to help 132 # This shit is fucked, disables ^C etc., and threading doesn't seem to help
130 # 133 #
131 134

mercurial