1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# coding: UTF-8
# Copyright 2009 Thomas Jourdan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
import ka_debug
import ka_extensionpoint
TOPIC_COLLABORATION = 1000
SUB_ID = 1
SUB_SHARE = 2
SUB_TUBES = 3
SUB_BUDDIES_PARTICIPATING = 4
SUB_BUDDIES_JOINED = 5
SUB_BUDDIES_LEFT = 6
SUB_RECEIVED = 7
SUB_BUDDIES_FOUND = 8
TOPIC_TASK = 2000
SUB_UNFINISHED = 1
TOPIC_ACTIVTY = 9000
SUB_REVISION = 1
TOPIC = {TOPIC_COLLABORATION: _('Collaboration'),
TOPIC_COLLABORATION+SUB_ID: _('My ID'),
TOPIC_COLLABORATION+SUB_SHARE: _('Share'),
TOPIC_COLLABORATION+SUB_TUBES: _('My tubes'),
TOPIC_COLLABORATION+SUB_BUDDIES_PARTICIPATING: _('Buddies participating'),
TOPIC_COLLABORATION+SUB_BUDDIES_JOINED: _('Buddies joined'),
TOPIC_COLLABORATION+SUB_BUDDIES_LEFT: _('Buddies left'),
TOPIC_COLLABORATION+SUB_RECEIVED: _('Received latest'),
TOPIC_COLLABORATION+SUB_BUDDIES_FOUND: _('Buddies found during startup'),
TOPIC_TASK: _('Tasks'),
TOPIC_TASK+SUB_UNFINISHED: _('Unfinished tasks'),
TOPIC_ACTIVTY: _('Activity'),
TOPIC_ACTIVTY+SUB_REVISION: _('Running'),
}
class Status(object):
"""
inv: self._status_dict is not None
"""
_status = None
def __init__(self):
"""
"""
self._dirty_flag = True
self._status_dict = {}
value = 'Kandid, release v' + str(ka_extensionpoint.revision_number)
value = value + ', DoB activated' if ka_debug.is_DbC_activated \
else value
self.set(TOPIC_ACTIVTY, SUB_REVISION, value)
@staticmethod
def instance():
if Status._status is None:
Status._status = Status()
return Status._status
def set(self, topic, sub, value):
"""
pre: topic >= 1000 and topic <= TOPIC_ACTIVTY and topic % 1000 == 0
pre: sub > 0 and sub < 1000
pre: value is not None
"""
self._dirty_flag = True
if str(type(value)) == "<type 'set'>":
self._status_dict[topic+sub] = str(value)[5:-2]
elif str(type(value)) == "<type 'list'>":
self._status_dict[topic+sub] = str(value)[1:-1]
else:
self._status_dict[topic+sub] = value
def isDirty(self):
return self._dirty_flag
def recall(self):
"""
post: __return__ is not None
"""
self._dirty_flag = False
keys = self._status_dict.keys()
keys.sort()
text = ''
topic_head = 0
for key in keys:
if not key / 1000 == topic_head:
text += '\n' + TOPIC[key - key % 1000] + '\n'
topic_head = key / 1000
text += ' ' + TOPIC[key] + ': ' + self._status_dict[key] + '\n'
return text
|