Tue, 06 Feb 2018 20:16:59 +0000
Changed dreamtime calculation.
The monotonic clock (time.monotonic()) sometimes advances unreliably
in sleep, so isn't reliable for calculating sleeping time. We have to
use time.time(). But this may be changed by the user, so we only use
it to track sleep periods, and still use time.monotonic() to track
wake periods.
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | # |
89
51cc2e25af38
Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents:
87
diff
changeset
|
2 | # Borgend by Tuomo Valkonen, 2018 |
51cc2e25af38
Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents:
87
diff
changeset
|
3 | # |
51cc2e25af38
Added author information headers and content information to source files
Tuomo Valkonen <tuomov@iki.fi>
parents:
87
diff
changeset
|
4 | # Borgend MacOS tray icon UI |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | # |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | import rumps |
10 | 8 | import time |
9 | import datetime | |
86
2fe66644c50d
Can use logging.getLogger directly now after proper packageisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
85
diff
changeset
|
10 | import logging |
79
b075b3db3044
Cleaned up module organisation to simplify borgend.py and not have to import it in other modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
78
diff
changeset
|
11 | import objc |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
12 | import math |
79
b075b3db3044
Cleaned up module organisation to simplify borgend.py and not have to import it in other modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
78
diff
changeset
|
13 | from threading import Lock, Timer |
b075b3db3044
Cleaned up module organisation to simplify borgend.py and not have to import it in other modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
78
diff
changeset
|
14 | |
80
a409242121d5
Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
79
diff
changeset
|
15 | from . import backup |
a409242121d5
Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
79
diff
changeset
|
16 | from . import dreamtime |
a409242121d5
Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
79
diff
changeset
|
17 | from . import branding |
99
281bab8361c8
Oops, log display wasn't working due to missing import
Tuomo Valkonen <tuomov@iki.fi>
parents:
98
diff
changeset
|
18 | from . import loggers |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
19 | from .exprotect import protect_noreturn |
80
a409242121d5
Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
79
diff
changeset
|
20 | from .config import settings |
10 | 21 | |
86
2fe66644c50d
Can use logging.getLogger directly now after proper packageisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
85
diff
changeset
|
22 | logger=logging.getLogger(__name__) |
31 | 23 | |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
24 | traynames_ok={ |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
25 | backup.State.INACTIVE: 'B.', |
98 | 26 | backup.State.PAUSED: 'B‖', |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
27 | backup.State.SCHEDULED: 'B.', |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
28 | backup.State.QUEUED: 'B:', |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
29 | backup.State.ACTIVE: 'B!', |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
30 | } |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
31 | |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
32 | traynames_errors={ |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
33 | # The first one should never be used |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
34 | backup.Errors.OK: traynames_ok[backup.State.INACTIVE], |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
35 | backup.Errors.BUSY: 'B⦙', |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
36 | backup.Errors.OFFLINE: 'B⦙', |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
37 | backup.Errors.ERRORS: 'B?' |
16
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
38 | } |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
39 | |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
40 | def trayname(ste): |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
41 | state=ste[0] |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
42 | errors=ste[1] |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
43 | if not errors.ok(): |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
44 | return traynames_errors[errors] |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
45 | else: |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
46 | return traynames_ok[state] |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
47 | |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
48 | def combine_state(a, b): |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
49 | return (max(a[0], b[0]), max(a[1], b[1])) |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
50 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
51 | # Refresh the menu at most once a second to reduce flicker |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
52 | refresh_interval=1.0 |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
53 | |
32 | 54 | # Workaround to rumps brokenness; |
55 | # see https://github.com/jaredks/rumps/issues/59 | |
56 | def notification_workaround(title, subtitle, message): | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
57 | try: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
58 | NSDictionary = objc.lookUpClass("NSDictionary") |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
59 | d=NSDictionary() |
32 | 60 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
61 | rumps.notification(title, subtitle, message, data=d) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
62 | except Exception as err: |
50 | 63 | logger.exception("Failed to display notification") |
32 | 64 | |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
65 | # Based on code snatched from |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
66 | # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
67 | def humanbytes(B): |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
68 | 'Return the given bytes as a human friendly KB, MB, GB, or TB string' |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
69 | B = float(B) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
70 | KB = float(1024) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
71 | MB = float(KB ** 2) # 1,048,576 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
72 | GB = float(KB ** 3) # 1,073,741,824 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
73 | TB = float(KB ** 4) # 1,099,511,627,776 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
74 | |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
75 | if B < KB: |
20
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
76 | return '{0}B'.format(B) |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
77 | elif KB <= B < MB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
78 | return '{0:.2f}KB'.format(B/KB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
79 | elif MB <= B < GB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
80 | return '{0:.2f}MB'.format(B/MB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
81 | elif GB <= B < TB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
82 | return '{0:.2f}GB'.format(B/GB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
83 | elif TB <= B: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
84 | return '{0:.2f}TB'.format(B/TB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
85 | |
97 | 86 | |
87 | def progress_percentage(done, total, d): | |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
88 | percentage = 100*float(done)/float(total) |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
89 | progress=': %d%%' % int(round(percentage)) |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
90 | if 'operation_no' in d: |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
91 | progress=':#%d%s' % (d['operation_no'], progress) |
97 | 92 | return progress |
93 | ||
94 | def progress_parts(done, total, d): | |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
95 | progress=': %d/%d' % (int(done), int(total)) |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
96 | if 'operation_no' in d: |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
97 | progress=':#%d%s' % (d['operation_no'], progress) |
97 | 98 | return progress |
99 | ||
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
100 | _error_state=(backup.State.INACTIVE, backup.Errors.ERRORS) |
97 | 101 | |
10 | 102 | def make_title(status): |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
103 | def add_info(info, new): |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
104 | if info: |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
105 | return "%s; %s" % (info, new) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
106 | else: |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
107 | return new |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
108 | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
109 | info=None |
105 | 110 | this_refresh_time=None |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
111 | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
112 | if not status.errors.ok(): |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
113 | info=add_info(info, str(status.errors)) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
114 | |
98 | 115 | if status.state==backup.State.PAUSED: |
116 | info=add_info(info, "paused") | |
117 | elif status.state==backup.State.SCHEDULED: | |
10 | 118 | # Operation scheduled |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
119 | when=status.when() |
10 | 120 | now=time.time() |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
121 | |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
122 | if when==math.inf: |
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
123 | whenstr='--' |
10 | 124 | else: |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
125 | tnow=datetime.datetime.fromtimestamp(now) |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
126 | twhen=datetime.datetime.fromtimestamp(when) |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
127 | tendtoday=twhen.replace(hour=23,minute=59,second=59) |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
128 | tendtomorrow=tendtoday+datetime.timedelta(days=1) |
10 | 129 | diff=datetime.timedelta(seconds=when-now) |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
130 | |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
131 | if twhen<tnow: |
111
c3bc27cf5ece
Changed dreamtime calculation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
110
diff
changeset
|
132 | whenstr='overdue' + (' on %s' % twhen.isoformat()) |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
133 | elif twhen>tendtomorrow: |
105 | 134 | # Display date if scheduled event is after tomorrow |
10 | 135 | whenday=datetime.date.fromtimestamp(when) |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
136 | whenstr='on %s' % twhen.date().isoformat() |
105 | 137 | this_refresh_time=tendtoday+datetime.timedelta(seconds=1) |
138 | elif twhen>tendtoday and diff.seconds>=12*60*60: # 12 hours | |
139 | # Display 'tomorrow' if the scheduled event is tomorrow and | |
140 | # not earlier than after 12 hours | |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
141 | whenstr='tomorrow' |
105 | 142 | this_refresh_time=twhen-datetime.timedelta(hours=12) |
10 | 143 | else: |
105 | 144 | # Otherwise, display time |
10 | 145 | twhen=time.localtime(when) |
146 | if twhen.tm_sec>30: | |
147 | # Round up minute display to avoid user confusion | |
148 | twhen=time.localtime(when+30) | |
149 | whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min) | |
38 | 150 | |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
151 | this_info='' |
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
152 | if 'reason' in status.detail: |
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
153 | this_info=status.detail['reason'] + ' ' |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
154 | |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
155 | when_how_sched= "%s%s %s" % (this_info, status.type, whenstr) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
156 | |
110
a79409c72565
Oops, removed stray reset of menu entry info
Tuomo Valkonen <tuomov@iki.fi>
parents:
106
diff
changeset
|
157 | info=add_info(info, when_how_sched) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
158 | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
159 | elif status.state==backup.State.QUEUED: |
97 | 160 | info=add_info(info, "queued %s" % status.type) |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
161 | elif status.state==backup.State.ACTIVE: |
10 | 162 | # Operation running |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
163 | progress='' |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
164 | d=status.detail |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
165 | if 'progress_current' in d and 'progress_total' in d: |
97 | 166 | progress=progress_percentage(d['progress_current'], |
167 | d['progress_total'], d) | |
168 | elif ('progress_current_secondary' in d and | |
169 | 'progress_total_secondary' in d): | |
170 | progress=progress_parts(d['progress_current_secondary'], | |
171 | d['progress_total_secondary'], d) | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
172 | elif 'original_size' in d and 'deduplicated_size' in d: |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
173 | progress=' %s→%s' % (humanbytes(d['original_size']), |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
174 | humanbytes(d['deduplicated_size'])) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
175 | |
97 | 176 | howrunning = "running %s%s" % (status.type, progress) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
177 | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
178 | info=add_info(info, howrunning) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
179 | else: |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
180 | pass |
15 | 181 | |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
182 | if info: |
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
183 | title=status.name + ' (' + info + ')' |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
184 | else: |
62
b7d13b2ad67e
Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
185 | title=status.name |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
186 | |
105 | 187 | return title, (status.state, status.errors), this_refresh_time |
10 | 188 | |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
189 | class BorgendTray(rumps.App): |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
190 | def __init__(self, backups): |
10 | 191 | self.lock=Lock() |
192 | self.backups=backups | |
76
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
193 | self.refresh_timer=None |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
194 | self.refresh_timer_time=None |
10 | 195 | self.statuses=[None]*len(backups) |
196 | ||
76
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
197 | for index in range(len(backups)): |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
198 | self.statuses[index]=backups[index].status() |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
199 | |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
200 | menu, title=self.build_menu_and_timer() |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
201 | |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
202 | super().__init__(title, menu=menu, quit_button=None) |
10 | 203 | |
76
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
204 | for index in range(len(backups)): |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
205 | # Python closures suck dog's balls; hence the _index=index hack |
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
206 | # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/ |
87
a214d475aa28
Better recovery from errors; fixes to potential race conditions in scheduler and repository queue
Tuomo Valkonen <tuomov@iki.fi>
parents:
86
diff
changeset
|
207 | cb=(lambda status, errorlog=None, _index=index: |
a214d475aa28
Better recovery from errors; fixes to potential race conditions in scheduler and repository queue
Tuomo Valkonen <tuomov@iki.fi>
parents:
86
diff
changeset
|
208 | self.__status_callback(_index, status, errorlog=errorlog)) |
76
4b08fca3ce34
Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
209 | backups[index].set_status_update_callback(cb) |
9
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
210 | |
101
3068b0de12ee
Part 2 of handling macOS sleep/wake signal brokenness.
Tuomo Valkonen <tuomov@iki.fi>
parents:
99
diff
changeset
|
211 | dreamtime.add_callback(self, self.__sleepwake_callback) |
10 | 212 | |
213 | def __rebuild_menu(self): | |
214 | menu=[] | |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
215 | state=(backup.State.INACTIVE, backup.Errors.OK) |
105 | 216 | refresh_time=None |
98 | 217 | all_paused=True |
218 | ||
10 | 219 | for index in range(len(self.backups)): |
220 | b=self.backups[index] | |
105 | 221 | title, this_state, this_refresh_time=make_title(self.statuses[index]) |
10 | 222 | # Python closures suck dog's balls... |
223 | # first and the last program I write in Python until somebody | |
224 | # fixes this brain damage | |
225 | cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b) | |
226 | item=rumps.MenuItem(title, callback=cbm) | |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
227 | if not this_state[1].ok(): |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
228 | item.state=-1 |
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
229 | elif this_state[0]==backup.State.SCHEDULED or this_state[0]==backup.State.QUEUED: |
38 | 230 | item.state=1 |
10 | 231 | menu.append(item) |
61
bc6c3d74e6ea
Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents:
55
diff
changeset
|
232 | state=combine_state(state, this_state) |
10 | 233 | |
98 | 234 | all_paused=(all_paused and this_state[0]==backup.State.PAUSED) |
235 | ||
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
236 | # Do we have to automatically update menu display? |
105 | 237 | if not refresh_time: |
238 | refresh_time=this_refresh_time | |
239 | elif this_refresh_time: | |
240 | refresh_time=min(refresh_time, this_refresh_time) | |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
241 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
242 | menu_log=rumps.MenuItem("Show log", callback=lambda _: showlog()) |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
243 | menu.append(menu_log) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
244 | |
98 | 245 | if all_paused: |
246 | pausename='Resume all' | |
247 | else: | |
248 | pausename="Pause all" | |
249 | menu_pause=rumps.MenuItem(pausename, callback=lambda _: self.pause_resume_all()) | |
250 | menu.append(menu_pause) | |
251 | ||
30
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
252 | if not settings['no_quit_menu_entry']: |
46
ecb41072a1b7
Unsuccesfull attempts at clean quit on exceptions that fall through
Tuomo Valkonen <tuomov@iki.fi>
parents:
45
diff
changeset
|
253 | menu_quit=rumps.MenuItem("Quit...", callback=lambda _: self.quit()) |
30
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
254 | menu.append(menu_quit) |
10 | 255 | |
105 | 256 | return menu, state, refresh_time |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
257 | |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
258 | def build_menu_and_timer(self): |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
259 | if self.refresh_timer: |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
260 | self.refresh_timer.cancel() |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
261 | self.refresh_timer=None |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
262 | self.refresh_timer_time=None |
105 | 263 | |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
264 | logger.debug('Rebuilding menu') |
105 | 265 | menu, state, refresh_time=self.__rebuild_menu() |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
266 | title=trayname(state) |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
267 | |
105 | 268 | if refresh_time: |
269 | # Need to time a refresh due to content display changing, | |
270 | # e.g., 'tomorrow' changing to a more specific hour. | |
271 | when=time.mktime(refresh_time.timetuple()) | |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
272 | delay=when-time.time() |
105 | 273 | if delay>0: |
274 | logger.debug('Timing menu refresh in %s seconds' % delay) | |
275 | self.refresh_timer=Timer(delay, self.refresh_ui) | |
276 | self.refresh_timer_time=refresh_time | |
277 | self.refresh_timer.start() | |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
278 | |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
279 | return menu, title |
10 | 280 | |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
281 | # Callbacks -- exception-protected to get any indications of errors |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
282 | |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
283 | @protect_noreturn |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
284 | def refresh_ui(self): |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
285 | with self.lock: |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
286 | menu, title=self.build_menu_and_timer() |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
287 | self.menu.clear() |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
288 | self.menu.update(menu) |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
289 | self.title=title |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
290 | |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
291 | @protect_noreturn |
55
407af23d16bb
Improved backup main thread loop, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
292 | def __status_callback(self, index, status, errorlog=None): |
75
2a44b9649212
UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
293 | logger.debug("Tray status callback") |
10 | 294 | with self.lock: |
295 | self.statuses[index]=status | |
75
2a44b9649212
UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
296 | # Time the refresh if it has not been timed, or if the timer |
2a44b9649212
UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
297 | # is timing for the "long-term" (refresh_timer_time set) |
2a44b9649212
UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
298 | if not self.refresh_timer or self.refresh_timer_time: |
105 | 299 | # logger.debug("Timing refresh") |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
300 | self.refresh_timer=Timer(refresh_interval, self.refresh_ui) |
72
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
301 | # refresh_timer_time is only set for "long-term timers" |
e0e6043779e2
Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents:
62
diff
changeset
|
302 | self.refresh_timer_time=None |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
303 | self.refresh_timer.start() |
10 | 304 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
305 | if errorlog: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
306 | if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str): |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
307 | msgid='UnknownError' |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
308 | else: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
309 | msgid=errorlog['msgid'] |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
310 | |
32 | 311 | logger.debug("Opening notification for error %s '%s'", |
312 | msgid, errorlog['message']) | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
313 | |
79
b075b3db3044
Cleaned up module organisation to simplify borgend.py and not have to import it in other modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
78
diff
changeset
|
314 | notification_workaround(branding.appname_stylised, |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
315 | msgid, errorlog['message']) |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
316 | |
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
317 | @protect_noreturn |
98 | 318 | def pause_resume_all(self): |
319 | with self.lock: | |
320 | try: | |
321 | all_paused=True | |
322 | for b in self.backups: | |
323 | all_paused=all_paused and b.is_paused() | |
324 | if all_paused: | |
325 | logger.debug('Pausing all') | |
326 | for b in self.backups: | |
327 | b.resume() | |
328 | else: | |
329 | logger.debug('Resuming all') | |
330 | for b in self.backups: | |
331 | b.pause() | |
332 | except: | |
333 | logger.exception("Pause/resume error") | |
334 | ||
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
335 | @protect_noreturn |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
336 | def __sleepwake_callback(self, woke): |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
337 | if woke: |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
338 | self.refresh_ui() |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
339 | |
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
340 | @protect_noreturn |
46
ecb41072a1b7
Unsuccesfull attempts at clean quit on exceptions that fall through
Tuomo Valkonen <tuomov@iki.fi>
parents:
45
diff
changeset
|
341 | def quit(self): |
28 | 342 | rumps.quit_application() |
343 | ||
106
a7bdc239ef62
Added exeption protection decorators to callbacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
105
diff
changeset
|
344 | @protect_noreturn |
28 | 345 | def __menu_select_backup(self, sender, b): |
346 | #sender.state=not sender.state | |
31 | 347 | logger.debug("Manually backup '%s'", b.name) |
32 | 348 | try: |
49 | 349 | b.create() |
32 | 350 | except Exception as err: |
50 | 351 | logger.exception("Failure to initialise backup") |
79
b075b3db3044
Cleaned up module organisation to simplify borgend.py and not have to import it in other modules.
Tuomo Valkonen <tuomov@iki.fi>
parents:
78
diff
changeset
|
352 | notification_workaround(branding.appname_stylised, |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
353 | err.__class__.__name__, str(err)) |
28 | 354 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
355 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
356 | # Log window |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
357 | # |
10 | 358 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
359 | logwindow=[None] |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
360 | logwindow_lock=Lock() |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
361 | |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
362 | def showlog(): |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
363 | try: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
364 | w=None |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
365 | with logwindow_lock: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
366 | if not logwindow[0]: |
84
b613265bd679
A few things had not been updated to module reorganisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
80
diff
changeset
|
367 | lines=loggers.fifo.formatAll() |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
368 | msg="\n".join(lines[0:]) |
84
b613265bd679
A few things had not been updated to module reorganisation
Tuomo Valkonen <tuomov@iki.fi>
parents:
80
diff
changeset
|
369 | w=rumps.Window(title=branding.appname_stylised+' log', |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
370 | default_text=msg, |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
371 | ok='Close', |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
372 | dimensions=(640,320)) |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
373 | logwindow[0]=w |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
374 | if w: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
375 | try: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
376 | w.run() |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
377 | finally: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
378 | with logwindow_lock: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
379 | logwindow[0]=None |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
380 | except Exception as err: |
50 | 381 | logger.exception("Failed to display log") |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
382 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
383 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
384 | # Notification click response => show log window |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
385 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
386 | |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
387 | @rumps.notifications |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
388 | def notification_center(_): |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
389 | showlog() |
50 | 390 |