5 """Keep track of recent operations, for a status display."""
8 MAX_DOWNLOAD_STATUSES = 10
9 MAX_UPLOAD_STATUSES = 10
10 MAX_MAPUPDATE_STATUSES = 20
11 MAX_PUBLISH_STATUSES = 20
12 MAX_RETRIEVE_STATUSES = 20
14 def __init__(self, stats_provider=None):
15 self.stats_provider = stats_provider
17 self.all_downloads_statuses = weakref.WeakKeyDictionary()
18 self.recent_download_statuses = []
19 self.all_upload_statuses = weakref.WeakKeyDictionary()
20 self.recent_upload_statuses = []
22 self.all_mapupdate_status = weakref.WeakKeyDictionary()
23 self.recent_mapupdate_status = []
24 self.all_publish_status = weakref.WeakKeyDictionary()
25 self.recent_publish_status = []
26 self.all_retrieve_status = weakref.WeakKeyDictionary()
27 self.recent_retrieve_status = []
29 self.all_helper_upload_statuses = weakref.WeakKeyDictionary()
30 self.recent_helper_upload_statuses = []
33 def add_download(self, download_status):
34 self.all_downloads_statuses[download_status] = None
35 self.recent_download_statuses.append(download_status)
36 while len(self.recent_download_statuses) > self.MAX_DOWNLOAD_STATUSES:
37 self.recent_download_statuses.pop(0)
39 def list_all_download_statuses(self):
40 for ds in self.all_downloads_statuses:
43 def add_upload(self, upload_status):
44 self.all_upload_statuses[upload_status] = None
45 self.recent_upload_statuses.append(upload_status)
46 while len(self.recent_upload_statuses) > self.MAX_UPLOAD_STATUSES:
47 self.recent_upload_statuses.pop(0)
49 def list_all_upload_statuses(self):
50 for us in self.all_upload_statuses:
55 def notify_mapupdate(self, p):
56 self.all_mapupdate_status[p] = None
57 self.recent_mapupdate_status.append(p)
58 while len(self.recent_mapupdate_status) > self.MAX_MAPUPDATE_STATUSES:
59 self.recent_mapupdate_status.pop(0)
61 def notify_publish(self, p, size):
62 self.all_publish_status[p] = None
63 self.recent_publish_status.append(p)
64 if self.stats_provider:
65 self.stats_provider.count('mutable.files_published', 1)
66 # We must be told bytes_published as an argument, since the
67 # publish_status does not yet know how much data it will be asked
68 # to send. When we move to MDMF we'll need to find a better way
70 self.stats_provider.count('mutable.bytes_published', size)
71 while len(self.recent_publish_status) > self.MAX_PUBLISH_STATUSES:
72 self.recent_publish_status.pop(0)
74 def notify_retrieve(self, r):
75 self.all_retrieve_status[r] = None
76 self.recent_retrieve_status.append(r)
77 if self.stats_provider:
78 self.stats_provider.count('mutable.files_retrieved', 1)
79 self.stats_provider.count('mutable.bytes_retrieved', r.get_size())
80 while len(self.recent_retrieve_status) > self.MAX_RETRIEVE_STATUSES:
81 self.recent_retrieve_status.pop(0)
84 def list_all_mapupdate_statuses(self):
85 for s in self.all_mapupdate_status:
87 def list_all_publish_statuses(self):
88 for s in self.all_publish_status:
90 def list_all_retrieve_statuses(self):
91 for s in self.all_retrieve_status:
94 def notify_helper_upload(self, s):
95 self.all_helper_upload_statuses[s] = None
96 self.recent_helper_upload_statuses.append(s)
97 while len(self.recent_helper_upload_statuses) > self.MAX_UPLOAD_STATUSES:
98 self.recent_helper_upload_statuses.pop(0)
100 def list_all_helper_statuses(self):
101 for s in self.all_helper_upload_statuses: