| 8 import logging |
8 import logging |
| 9 from threading import Lock |
9 from threading import Lock |
| 10 |
10 |
| 11 INACTIVE=0 |
11 INACTIVE=0 |
| 12 ACTIVE=1 |
12 ACTIVE=1 |
| 13 ERROR=2 |
13 ERRORS=2 |
| 14 |
14 |
| 15 traynames={INACTIVE: 'B.', ACTIVE: 'B!', ERROR: 'B?'} |
15 traynames={INACTIVE: 'B.', ACTIVE: 'B!', ERRORS: 'B?'} |
| 16 |
16 |
| 17 def combine_state(state1, state2): |
17 def combine_state(state1, state2): |
| 18 if state1==ERROR or state2==ERROR: |
18 if state1==ERRORS or state2==ERRORS: |
| 19 return ERROR |
19 return ERRORS |
| 20 elif state1==ACTIVE or state2==ACTIVE: |
20 elif state1==ACTIVE or state2==ACTIVE: |
| 21 return ACTIVE |
21 return ACTIVE |
| 22 else: |
22 else: |
| 23 return INACTIVE |
23 return INACTIVE |
| 24 |
24 |
| 25 def make_title(status): |
25 def make_title(status): |
| 26 state=INACTIVE |
26 state=INACTIVE |
| |
27 |
| 27 if status['type']=='scheduled': |
28 if status['type']=='scheduled': |
| 28 # Operation scheduled |
29 # Operation scheduled |
| 29 when=status['when'] |
30 when=status['when'] |
| 30 now=time.time() |
31 now=time.time() |
| 31 if when<now: |
32 if when<now: |
| 42 twhen=time.localtime(when+30) |
43 twhen=time.localtime(when+30) |
| 43 whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min) |
44 whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min) |
| 44 detail='' |
45 detail='' |
| 45 if 'detail' in status and status['detail']: |
46 if 'detail' in status and status['detail']: |
| 46 if status['detail']=='retry': |
47 if status['detail']=='retry': |
| 47 state=ERROR |
48 state=ERRORS |
| 48 detail=status['detail']+' ' |
49 detail=status['detail']+' ' |
| 49 title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
50 title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
| 50 elif status['type']=='current': |
51 elif status['type']=='current': |
| 51 # Operation running |
52 # Operation running |
| 52 progress='' |
53 progress='' |
| 55 title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
56 title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
| 56 active=ACTIVE |
57 active=ACTIVE |
| 57 else: # status['type']=='nothing': |
58 else: # status['type']=='nothing': |
| 58 # Should be unscheduled, nothing running |
59 # Should be unscheduled, nothing running |
| 59 title=status['name'] |
60 title=status['name'] |
| |
61 |
| |
62 if status['errors']: |
| |
63 state=ERRORS |
| 60 |
64 |
| 61 return title, state |
65 return title, state |
| 62 |
66 |
| 63 |
67 |
| 64 class BorgendTray(rumps.App): |
68 class BorgendTray(rumps.App): |