Sun, 21 Jan 2018 18:32:14 +0000
Just don't set a diffirent level for fifolog after all
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | # |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | # MacOS UI |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | # |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | import rumps |
10 | 6 | import time |
7 | import datetime | |
8 | import logging | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
9 | import borgend |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
10 | from threading import Lock, Timer |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
11 | from config import settings |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
12 | import objc |
10 | 13 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
14 | logger=borgend.logger.getChild(__name__) |
31 | 15 | |
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
|
16 | INACTIVE=0 |
38 | 17 | SCHEDULED_OK=1 |
18 | ACTIVE=2 | |
19 | OFFLINE=3 | |
20 | ERRORS=4 | |
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
|
21 | |
16
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
22 | traynames={ |
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
23 | INACTIVE: 'B.', |
38 | 24 | SCHEDULED_OK: 'B.', |
16
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
25 | ACTIVE: 'B!', |
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
26 | OFFLINE: 'B⦙', |
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
27 | ERRORS: 'B?' |
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
28 | } |
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
|
29 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
30 | # 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
|
31 | refresh_interval=1.0 |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
32 | |
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
|
33 | def combine_state(state1, state2): |
16
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
34 | return max(state1, state2) |
11
0bff53095f28
New tray title: B. or B! depending on activity
Tuomo Valkonen <tuomov@iki.fi>
parents:
10
diff
changeset
|
35 | |
32 | 36 | # Workaround to rumps brokenness; |
37 | # see https://github.com/jaredks/rumps/issues/59 | |
38 | def notification_workaround(title, subtitle, message): | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
39 | try: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
40 | NSDictionary = objc.lookUpClass("NSDictionary") |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
41 | d=NSDictionary() |
32 | 42 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
43 | rumps.notification(title, subtitle, message, data=d) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
44 | except Exception as err: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
45 | logger.debug('Unable to display notificaton:%s:%s',err.__class__.__name__, str(err)) |
32 | 46 | |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
47 | # Based on code snatched from |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
48 | # 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
|
49 | def humanbytes(B): |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
50 | '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
|
51 | B = float(B) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
52 | KB = float(1024) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
53 | 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
|
54 | 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
|
55 | 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
|
56 | |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
57 | if B < KB: |
20
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
58 | 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
|
59 | elif KB <= B < MB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
60 | 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
|
61 | elif MB <= B < GB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
62 | 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
|
63 | elif GB <= B < TB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
64 | 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
|
65 | elif TB <= B: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
66 | 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
|
67 | |
10 | 68 | def make_title(status): |
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
|
69 | state=INACTIVE |
15 | 70 | |
10 | 71 | if status['type']=='scheduled': |
72 | # Operation scheduled | |
73 | when=status['when'] | |
74 | now=time.time() | |
75 | if when<now: | |
76 | whenstr='overdue' | |
77 | else: | |
78 | diff=datetime.timedelta(seconds=when-now) | |
79 | if diff.days>0: | |
80 | whenday=datetime.date.fromtimestamp(when) | |
81 | whenstr='on %s' % whenday.isoformat() | |
82 | else: | |
83 | twhen=time.localtime(when) | |
84 | if twhen.tm_sec>30: | |
85 | # Round up minute display to avoid user confusion | |
86 | twhen=time.localtime(when+30) | |
87 | whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min) | |
38 | 88 | |
89 | if status['detail']=='normal': | |
90 | state=SCHEDULED_OK | |
91 | detail='' | |
92 | else: | |
93 | if status['detail']=='retry': | |
94 | state=ERRORS | |
95 | detail=status['detail']+' ' | |
11
0bff53095f28
New tray title: B. or B! depending on activity
Tuomo Valkonen <tuomov@iki.fi>
parents:
10
diff
changeset
|
96 | title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
10 | 97 | elif status['type']=='current': |
98 | # 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
|
99 | progress='' |
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
|
100 | if 'progress_current' in status and 'progress_total' in status: |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
101 | progress=' %d%%' % (status['progress_current']/status['progress_total']) |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
102 | elif 'original_size' in status and 'deduplicated_size' in status: |
20
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
103 | progress=' %s→%s' % (humanbytes(status['original_size']), |
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
104 | humanbytes(status['deduplicated_size'])) |
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
|
105 | title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
18 | 106 | state=ACTIVE |
10 | 107 | else: # status['type']=='nothing': |
108 | # Should be unscheduled, nothing running | |
11
0bff53095f28
New tray title: B. or B! depending on activity
Tuomo Valkonen <tuomov@iki.fi>
parents:
10
diff
changeset
|
109 | title=status['name'] |
38 | 110 | if status['errors']: |
111 | title=title + " (errors)" | |
11
0bff53095f28
New tray title: B. or B! depending on activity
Tuomo Valkonen <tuomov@iki.fi>
parents:
10
diff
changeset
|
112 | |
15 | 113 | if status['errors']: |
114 | state=ERRORS | |
115 | ||
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
|
116 | return title, state |
10 | 117 | |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
118 | 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
|
119 | def __init__(self, backups): |
10 | 120 | self.lock=Lock() |
121 | self.backups=backups | |
122 | self.statuses=[None]*len(backups) | |
123 | ||
124 | with self.lock: | |
125 | # Initialise reporting callbacks and local status copy | |
126 | # (since rumps doesn't seem to be able to update menu items | |
127 | # without rebuilding the whole menu, and we don't want to lock | |
128 | # when calling Backup.status(), especially as we will be called | |
129 | # from Backup reporting its status, we keep a copy to allow | |
130 | # rebuilding the entire menu | |
131 | for index in range(len(backups)): | |
132 | b=backups[index] | |
133 | # Python closures suck dog's balls; hence the _index=index hack | |
134 | # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/ | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
135 | cb=(lambda obj, status, _index=index, errors=None: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
136 | self.__status_callback(obj, _index, status, errors)) |
10 | 137 | b.set_status_update_callback(cb) |
138 | self.statuses[index]=b.status() | |
139 | ||
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
|
140 | menu, state=self.__rebuild_menu() |
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
|
141 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
142 | self.refresh_timer=None |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
143 | self.logwindow=None |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
144 | |
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
|
145 | super().__init__(traynames[state], menu=menu, quit_button=None) |
10 | 146 | |
147 | def __rebuild_menu(self): | |
148 | menu=[] | |
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
|
149 | state=INACTIVE |
10 | 150 | for index in range(len(self.backups)): |
151 | b=self.backups[index] | |
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
|
152 | title, this_state=make_title(self.statuses[index]) |
10 | 153 | # Python closures suck dog's balls... |
154 | # first and the last program I write in Python until somebody | |
155 | # fixes this brain damage | |
156 | cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b) | |
157 | item=rumps.MenuItem(title, callback=cbm) | |
38 | 158 | if this_state==SCHEDULED_OK: |
159 | item.state=1 | |
160 | elif this_state>=OFFLINE: | |
161 | item.state=-1 | |
10 | 162 | menu.append(item) |
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 | state=combine_state(state, this_state) |
10 | 164 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
165 | menu_log=rumps.MenuItem("Show log", callback=self.showlog) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
166 | menu.append(menu_log) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
167 | |
30
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
168 | if not settings['no_quit_menu_entry']: |
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
169 | menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit) |
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
170 | menu.append(menu_quit) |
10 | 171 | |
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
|
172 | return menu, state |
10 | 173 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
174 | def refresh_ui(self): |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
175 | with self.lock: |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
176 | self.refresh_timer=None |
31 | 177 | logger.debug('Rebuilding menu') |
28 | 178 | menu, active=self.__rebuild_menu() |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
179 | self.menu.clear() |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
180 | self.menu.update(menu) |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
181 | self.title=traynames[active] |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
182 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
183 | def __status_callback(self, obj, index, status, errorlog): |
31 | 184 | logger.debug('Status callbackup %s' % str(status)) |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
185 | |
10 | 186 | with self.lock: |
187 | self.statuses[index]=status | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
188 | if self.refresh_timer==None: |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
189 | self.refresh_timer=Timer(refresh_interval, self.refresh_ui) |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
190 | self.refresh_timer.start() |
10 | 191 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
192 | if errorlog: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
193 | 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
|
194 | msgid='UnknownError' |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
195 | else: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
196 | msgid=errorlog['msgid'] |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
197 | |
32 | 198 | logger.debug("Opening notification for error %s '%s'", |
199 | msgid, errorlog['message']) | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
200 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
201 | notification_workaround(borgend.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
|
202 | msgid, errorlog['message']) |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
203 | |
28 | 204 | def my_quit(self, _): |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
205 | logging.shutdown() |
28 | 206 | rumps.quit_application() |
207 | ||
208 | def __menu_select_backup(self, sender, b): | |
209 | #sender.state=not sender.state | |
31 | 210 | logger.debug("Manually backup '%s'", b.name) |
32 | 211 | try: |
212 | b.create(None) | |
213 | except Exception as err: | |
214 | logger.debug("Opening notification for exception %s '%s'", | |
215 | err.__class__.__name__, str(err)) | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
216 | notification_workaround(borgend.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
|
217 | err.__class__.__name__, str(err)) |
28 | 218 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
219 | @rumps.notifications |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
220 | def notification_center(data): |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
221 | pass |
10 | 222 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
223 | def showlog(self, _): |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
224 | try: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
225 | if not self.logwindow: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
226 | lines=borgend.fifolog.formatAll() |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
227 | msg="\n".join(lines[0:]) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
228 | self.logwindow=rumps.Window(title=borgend.appname_stylised+' log', |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
229 | default_text=msg, |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
230 | ok='Close', |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
231 | dimensions=(640,320)) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
232 | self.logwindow.run() |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
233 | # Does not return until closed |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
234 | self.logwindow=None |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
235 | except Exception as err: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
236 | logger.critical('%s:%s', err.__class__.__name__, str(err)) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
237 |