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