Sun, 21 Jan 2018 17:45:55 +0000
Improved error indicators
0 | 1 | #!/usr/local/bin/python3 |
2 | ||
4
d72c4844e791
Better borg output processing and some logging
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
3 | import logging |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
4 | from fifolog import FIFOHandler |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
5 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
6 | # |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
7 | # Branding |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
8 | # |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
9 | appname="borgend" |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
10 | appname_stylised="Borgend" |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
11 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
12 | # |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
13 | # Logging configuration |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
14 | # |
4
d72c4844e791
Better borg output processing and some logging
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
15 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
16 | loglevel=logging.DEBUG |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
17 | logfmt="%(asctime)s:%(levelname)s:%(name)s:%(message)s" |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
18 | fifolog_capacity=1000 |
36 | 19 | fifolog_level=logging.INFO |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
20 | fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s" |
4
d72c4844e791
Better borg output processing and some logging
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
21 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
22 | # |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
23 | # Setup logger |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
24 | # |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
25 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
26 | logger=logging.getLogger(appname) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
27 | logger.setLevel(loglevel) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
28 | logger.propagate=True |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
29 | fifolog=FIFOHandler(fifolog_capacity) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
30 | logger.addHandler(fifolog) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
31 | fifolog.setLevel(fifolog_level) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
32 | fifolog.setFormatter(logging.Formatter(fifolog_fmt)) |
31 | 33 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
34 | if __name__=="__main__": |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
35 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
36 | import logging.handlers |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
37 | import os |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
38 | import config |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
39 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
40 | if not os.path.isdir(config.logs_dir): |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
41 | os.makedirs(config.logs_dir) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
42 | |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
43 | handler=logging.handlers.TimedRotatingFileHandler( |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
44 | os.path.join(config.logs_dir, appname+'.log'), |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
45 | when='D', interval=1) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
46 | handler.setFormatter(logging.Formatter(logfmt)) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
47 | logger.addHandler(handler) |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
48 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
49 | from threading import Thread |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
50 | from backup import Backup |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
51 | from queue import Queue |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
52 | from ui import BorgendTray |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
53 | import signal, os |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
54 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
55 | backupconfigs=config.settings['backups'] |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
56 | backups=[None]*len(backupconfigs); |
3
4cad934aa9ce
Can launch borg now; output not yet processed
Tuomo Valkonen <tuomov@iki.fi>
parents:
2
diff
changeset
|
57 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
58 | for i in range(len(backupconfigs)): |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
59 | logger.info('Setting up backup set %d' % i) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
60 | backups[i]=Backup(i, backupconfigs[i]) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
61 | backups[i].schedule() |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
62 | |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
31
diff
changeset
|
63 | tray=BorgendTray(backups); |
9
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
64 | tray.run() |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
65 | |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
66 | # |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
67 | # This shit is fucked, disables ^C etc., and threading doesn't seem to help |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
68 | # |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
69 | |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
70 | # ui_thread=Thread(target=tray.run) |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
71 | # ui_thread.daemon=True |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
72 | # ui_thread.start() |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
73 | |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
74 | # def quit_signal_handler(signum, frame): |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
75 | # print('Signal handler called with signal %s' % str(signum)) |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
76 | # ui_thread.terminate() |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
77 | # os.exit() |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
78 | |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
79 | # signal.signal(signal.SIGTERM, quit_signal_handler) |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
80 | # signal.signal(signal.SIGINT, quit_signal_handler) |
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
81 |