borgend/ui.py

Mon, 29 Jan 2018 09:38:53 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 29 Jan 2018 09:38:53 +0000
changeset 89
51cc2e25af38
parent 87
a214d475aa28
child 97
96d5adbe0205
permissions
-rw-r--r--

Added author information headers and content information to source files

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
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
8 import time
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
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
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
12 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
13
80
a409242121d5 Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 79
diff changeset
14 from . import backup
a409242121d5 Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 79
diff changeset
15 from . import dreamtime
a409242121d5 Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 79
diff changeset
16 from . import branding
a409242121d5 Better package-like organisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 79
diff changeset
17 from .config import settings
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
18
86
2fe66644c50d Can use logging.getLogger directly now after proper packageisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 85
diff changeset
19 logger=logging.getLogger(__name__)
31
b4b4bb7a2ec5 More logging detail
Tuomo Valkonen <tuomov@iki.fi>
parents: 30
diff changeset
20
61
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
21 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
22 backup.State.INACTIVE: 'B.',
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
23 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
24 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
25 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
26 }
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
27
61
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
28 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
29 # 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
30 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
31 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
32 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
33 backup.Errors.ERRORS: 'B?'
16
d0ffae5550ef Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents: 15
diff changeset
34 }
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
35
61
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
36 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
37 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
38 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
39 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
40 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
41 else:
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
42 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
43
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
44 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
45 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
46
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
47 # 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
48 refresh_interval=1.0
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
49
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
50 # Workaround to rumps brokenness;
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
51 # see https://github.com/jaredks/rumps/issues/59
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
52 def notification_workaround(title, subtitle, message):
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
53 try:
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
54 NSDictionary = objc.lookUpClass("NSDictionary")
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
55 d=NSDictionary()
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
56
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
57 rumps.notification(title, subtitle, message, data=d)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
58 except Exception as err:
50
2d8947351727 Logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
59 logger.exception("Failed to display notification")
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
60
19
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
61 # Based on code snatched from
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
62 # 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
63 def humanbytes(B):
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
64 '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
65 B = float(B)
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
66 KB = float(1024)
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
67 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
68 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
69 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
70
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
71 if B < KB:
20
fdfbe5d7b677 Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents: 19
diff changeset
72 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
73 elif KB <= B < MB:
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
74 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
75 elif MB <= B < GB:
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
76 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
77 elif GB <= B < TB:
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
78 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
79 elif TB <= B:
f9ce2442f14f Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents: 18
diff changeset
80 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
81
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
82 def make_title(status):
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
83 def add_info(info, new):
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
84 if info:
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
85 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
86 else:
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
87 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
88
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
89 info=None
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
90 this_need_reconstruct=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
91
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
92 if not status.errors.ok():
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
93 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
94
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
95 if status.state==backup.State.SCHEDULED:
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
96 # Operation scheduled
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
97 when=status.when()
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
98 now=time.time()
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
99
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
100 if when<now:
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
101 whenstr='overdue'
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
102 info=''
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
103 else:
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
104 tnow=datetime.datetime.fromtimestamp(now)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
105 twhen=datetime.datetime.fromtimestamp(when)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
106 tendtoday=twhen.replace(hour=23,minute=59,second=59)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
107 tendtomorrow=tendtoday+datetime.timedelta(days=1)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
108 diff=datetime.timedelta(seconds=when-now)
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
109
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
110 if twhen>tendtomorrow:
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
111 whenday=datetime.date.fromtimestamp(when)
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
112 whenstr='on %s' % twhen.date().isoformat()
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
113 this_need_reconstruct=tendtoday+datetime.timedelta(seconds=1)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
114 elif diff.seconds>=12*60*60: # 12 hours
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
115 whenstr='tomorrow'
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
116 this_need_reconstruct=twhen-datetime.timedelta(hours=12)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
117 else:
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
118 twhen=time.localtime(when)
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
119 if twhen.tm_sec>30:
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
120 # Round up minute display to avoid user confusion
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
121 twhen=time.localtime(when+30)
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
122 whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min)
38
085a635f23f5 Improved error indicators
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
123
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
124 this_info=''
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
125 if 'reason' in status.detail:
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
126 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
127
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
128 when_how_sched= "%s%s %s" % (this_info, status.operation, 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
129
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
130 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
131
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
132 elif status.state==backup.State.QUEUED:
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
133 info=add_info(info, "queued")
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
134 elif status.state==backup.State.ACTIVE:
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
135 # 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
136 progress=''
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
137 d=status.detail
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
138 if 'progress_current' in d and 'progress_total' in d:
85
56a000d15965 On startup, for better scheduling, obtain previous backup time with 'borg list'
Tuomo Valkonen <tuomov@iki.fi>
parents: 84
diff changeset
139 percentage = 100*float(d['progress_current'])/float(d['progress_total'])
56a000d15965 On startup, for better scheduling, obtain previous backup time with 'borg list'
Tuomo Valkonen <tuomov@iki.fi>
parents: 84
diff changeset
140 progress=': %d%%' % int(round(percentage))
56a000d15965 On startup, for better scheduling, obtain previous backup time with 'borg list'
Tuomo Valkonen <tuomov@iki.fi>
parents: 84
diff changeset
141 if 'operation_no' in d:
56a000d15965 On startup, for better scheduling, obtain previous backup time with 'borg list'
Tuomo Valkonen <tuomov@iki.fi>
parents: 84
diff changeset
142 progress='/#%d%s' % (d['operation_no'], progress)
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
143 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
144 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
145 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
146
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
147 howrunning = "running %s%s" % (status.operation, 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
148
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
149 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
150 else:
bc6c3d74e6ea Made combination error-state into an error-state matrix, as well as Enum
Tuomo Valkonen <tuomov@iki.fi>
parents: 55
diff changeset
151 pass
15
aaf1a281a3fe More error reporting
Tuomo Valkonen <tuomov@iki.fi>
parents: 14
diff changeset
152
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
153 if info:
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
154 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
155 else:
62
b7d13b2ad67e Turned Status and Operation into classes instead of dictionaries
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
156 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
157
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
158 return title, (status.state, status.errors), this_need_reconstruct
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
159
1
4cdc9c1f6b28 basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
160 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
161 def __init__(self, backups):
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
162 self.lock=Lock()
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
163 self.backups=backups
76
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
164 self.refresh_timer=None
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
165 self.refresh_timer_time=None
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
166 self.statuses=[None]*len(backups)
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
167
76
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
168 for index in range(len(backups)):
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
169 self.statuses[index]=backups[index].status()
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
170
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
171 menu, title=self.build_menu_and_timer()
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
172
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
173 super().__init__(title, menu=menu, quit_button=None)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
174
76
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
175 for index in range(len(backups)):
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
176 # 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
177 # 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
178 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
179 self.__status_callback(_index, status, errorlog=errorlog))
76
4b08fca3ce34 Dreamtime scheduling: discount system sleep periods
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
180 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
181
78
83b43987e61e Renamed the "sleep" module "dreamtime"
Tuomo Valkonen <tuomov@iki.fi>
parents: 76
diff changeset
182 dreamtime.add_callback(self, self.refresh_ui)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
183
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
184 def __rebuild_menu(self):
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
185 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
186 state=(backup.State.INACTIVE, backup.Errors.OK)
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
187 need_reconstruct=None
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
188 for index in range(len(self.backups)):
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
189 b=self.backups[index]
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
190 title, this_state, this_need_reconstruct=make_title(self.statuses[index])
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
191 # Python closures suck dog's balls...
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
192 # first and the last program I write in Python until somebody
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
193 # fixes this brain damage
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
194 cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b)
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
195 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
196 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
197 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
198 elif this_state[0]==backup.State.SCHEDULED or this_state[0]==backup.State.QUEUED:
38
085a635f23f5 Improved error indicators
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
199 item.state=1
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
200 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
201 state=combine_state(state, this_state)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
202
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
203 # Do we have to automatically update menu display?
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
204 if not need_reconstruct:
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
205 need_reconstruct=this_need_reconstruct
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
206 elif this_need_reconstruct:
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
207 need_reconstruct=min(need_reconstruct, this_need_reconstruct)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
208
42
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
209 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
210 menu.append(menu_log)
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
211
30
3dd525652dc8 Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
212 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
213 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
214 menu.append(menu_quit)
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
215
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
216 return menu, state, need_reconstruct
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
217
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
218 def build_menu_and_timer(self):
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
219 if self.refresh_timer:
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
220 self.refresh_timer.cancel()
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
221 self.refresh_timer=None
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
222 self.refresh_timer_time=None
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
223 logger.debug('Rebuilding menu')
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
224 menu, state, need_reconstruct=self.__rebuild_menu()
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
225 title=trayname(state)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
226
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
227 if need_reconstruct:
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
228 when=time.mktime(need_reconstruct.timetuple())
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
229 delay=when-time.time()
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
230 self.refresh_timer=Timer(delay, self.refresh_ui)
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
231 self.refresh_timer_time=need_reconstruct
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
232 self.refresh_timer.start()
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
233
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
234 return menu, title
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
235
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
236 def refresh_ui(self):
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
237 with self.lock:
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
238 menu, title=self.build_menu_and_timer()
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
239 self.menu.clear()
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
240 self.menu.update(menu)
72
e0e6043779e2 Improved time display in menu
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
241 self.title=title
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
242
55
407af23d16bb Improved backup main thread loop, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 51
diff changeset
243 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
244 logger.debug("Tray status callback")
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
245 with self.lock:
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
246 self.statuses[index]=status
75
2a44b9649212 UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
247 # 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
248 # 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
249 if not self.refresh_timer or self.refresh_timer_time:
2a44b9649212 UI refresh fix; added debug messages
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
250 logger.debug("Timing refresh")
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
251 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
252 # 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
253 self.refresh_timer_time=None
27
a347387868be UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents: 21
diff changeset
254 self.refresh_timer.start()
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
255
21
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
256 if errorlog:
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
257 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
258 msgid='UnknownError'
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
259 else:
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
260 msgid=errorlog['msgid']
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
261
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
262 logger.debug("Opening notification for error %s '%s'",
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
263 msgid, errorlog['message'])
21
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
264
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
265 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
266 msgid, errorlog['message'])
21
c36e549a7f12 Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents: 20
diff changeset
267
46
ecb41072a1b7 Unsuccesfull attempts at clean quit on exceptions that fall through
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
268 def quit(self):
28
a7c56424e867 Reorder
Tuomo Valkonen <tuomov@iki.fi>
parents: 27
diff changeset
269 rumps.quit_application()
a7c56424e867 Reorder
Tuomo Valkonen <tuomov@iki.fi>
parents: 27
diff changeset
270
a7c56424e867 Reorder
Tuomo Valkonen <tuomov@iki.fi>
parents: 27
diff changeset
271 def __menu_select_backup(self, sender, b):
a7c56424e867 Reorder
Tuomo Valkonen <tuomov@iki.fi>
parents: 27
diff changeset
272 #sender.state=not sender.state
31
b4b4bb7a2ec5 More logging detail
Tuomo Valkonen <tuomov@iki.fi>
parents: 30
diff changeset
273 logger.debug("Manually backup '%s'", b.name)
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
274 try:
49
db33dfa64ad6 Improved scheduler
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
275 b.create()
32
06fc14211ba9 Error handling improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 31
diff changeset
276 except Exception as err:
50
2d8947351727 Logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
277 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
278 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
279 err.__class__.__name__, str(err))
28
a7c56424e867 Reorder
Tuomo Valkonen <tuomov@iki.fi>
parents: 27
diff changeset
280
42
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
281 #
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
282 # Log window
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
283 #
10
76dbfb06eba0 Semi-working menu items.
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
284
42
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
285 logwindow=[None]
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
286 logwindow_lock=Lock()
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
287
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
288 def showlog():
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
289 try:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
290 w=None
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
291 with logwindow_lock:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
292 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
293 lines=loggers.fifo.formatAll()
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
294 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
295 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
296 default_text=msg,
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
297 ok='Close',
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
298 dimensions=(640,320))
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
299 logwindow[0]=w
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
300 if w:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
301 try:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
302 w.run()
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
303 finally:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
304 with logwindow_lock:
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
305 logwindow[0]=None
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
306 except Exception as err:
50
2d8947351727 Logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
307 logger.exception("Failed to display log")
34
9fce700d42de Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 33
diff changeset
308
42
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
309 #
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
310 # 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
311 #
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
312
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
313 @rumps.notifications
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
314 def notification_center(_):
00accd11978b Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents: 40
diff changeset
315 showlog()
50
2d8947351727 Logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
316

mercurial