28 # Setup logger, needed by the config module to be loaded next |
27 # Setup logger, needed by the config module to be loaded next |
29 # |
28 # |
30 |
29 |
31 logger=logging.getLogger(appname) |
30 logger=logging.getLogger(appname) |
32 logger.setLevel(loglevel) |
31 logger.setLevel(loglevel) |
|
32 stderrlog=logging.StreamHandler() |
|
33 logger.addHandler(stderrlog) |
33 logger.propagate=True |
34 logger.propagate=True |
|
35 |
|
36 # |
|
37 # Import our own modules. This needs to be done here |
|
38 # for the things above to be available to them |
|
39 # |
|
40 |
|
41 import config |
|
42 from scheduler import Scheduler |
|
43 from fifolog import FIFOHandler |
34 |
44 |
35 # |
45 # |
36 # Argument processing |
46 # Argument processing |
37 # |
47 # |
38 |
|
39 import config |
|
40 |
48 |
41 def do_args(): |
49 def do_args(): |
42 parser=argparse.ArgumentParser( |
50 parser=argparse.ArgumentParser( |
43 description=appname_stylised + ': BorgBackup scheduler and tray icon.', |
51 description=appname_stylised + ': BorgBackup scheduler and tray icon.', |
44 epilog='Configuration file location:\n\n %s\n ' % config.cfgfile, |
52 epilog='Configuration file location:\n\n %s\n ' % config.cfgfile, |
84 import signal, os |
92 import signal, os |
85 |
93 |
86 backupconfigs=config.settings['backups'] |
94 backupconfigs=config.settings['backups'] |
87 backups=[None]*len(backupconfigs); |
95 backups=[None]*len(backupconfigs); |
88 |
96 |
|
97 scheduler = Scheduler() |
|
98 |
89 try: |
99 try: |
|
100 scheduler.start() |
|
101 |
90 for i in range(len(backupconfigs)): |
102 for i in range(len(backupconfigs)): |
91 logger.info('Setting up backup set %d' % i) |
103 logger.info('Setting up backup set %d' % i) |
92 backups[i]=Backup(i, backupconfigs[i]) |
104 backups[i]=Backup(i, backupconfigs[i], scheduler) |
93 backups[i].schedule() |
105 backups[i].start() |
94 |
106 |
95 if args.notray or platform.system()!='Darwin': |
107 if args.notray or platform.system()!='Darwin': |
96 pass |
108 pass |
97 else: |
109 else: |
98 from ui import BorgendTray |
110 from ui import BorgendTray |
102 for i in range(len(backups)): |
114 for i in range(len(backups)): |
103 if backups[i]: |
115 if backups[i]: |
104 backups[i].abort() |
116 backups[i].abort() |
105 backups=[] |
117 backups=[] |
106 except Exception as err: |
118 except Exception as err: |
|
119 # TODO: Should write errors here to stderr; |
|
120 # perhaps add an extra stderr logger for error level messages |
107 utils.log_exception(logger, err, detail='Exiting') |
121 utils.log_exception(logger, err, detail='Exiting') |
108 if tray: |
122 if tray: |
109 tray.quit() |
123 tray.quit() |
110 else: |
124 else: |
111 logging.shutdown() |
125 logging.shutdown() |