]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/web/status.py
helper stats: fix the /helper_status page, the recent conflict merging missed some...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / web / status.py
1
2 import time
3 import simplejson
4 from twisted.internet import defer
5 from nevow import rend, inevow, tags as T
6 from allmydata.util import base32, idlib
7 from allmydata.web.common import IClient, getxmlfile, abbreviate_time, \
8      abbreviate_rate, get_arg
9 from allmydata.interfaces import IUploadStatus, IDownloadStatus, \
10      IPublishStatus, IRetrieveStatus
11
12 def plural(sequence_or_length):
13     if isinstance(sequence_or_length, int):
14         length = sequence_or_length
15     else:
16         length = len(sequence_or_length)
17     if length == 1:
18         return ""
19     return "s"
20
21 class RateAndTimeMixin:
22
23     def render_time(self, ctx, data):
24         return abbreviate_time(data)
25
26     def render_rate(self, ctx, data):
27         return abbreviate_rate(data)
28
29 class UploadResultsRendererMixin(RateAndTimeMixin):
30     # this requires a method named 'upload_results'
31
32     def render_pushed_shares(self, ctx, data):
33         d = self.upload_results()
34         d.addCallback(lambda res: res.pushed_shares)
35         return d
36
37     def render_preexisting_shares(self, ctx, data):
38         d = self.upload_results()
39         d.addCallback(lambda res: res.preexisting_shares)
40         return d
41
42     def render_sharemap(self, ctx, data):
43         d = self.upload_results()
44         d.addCallback(lambda res: res.sharemap)
45         def _render(sharemap):
46             if sharemap is None:
47                 return "None"
48             l = T.ul()
49             for shnum in sorted(sharemap.keys()):
50                 l[T.li["%d -> %s" % (shnum, sharemap[shnum])]]
51             return l
52         d.addCallback(_render)
53         return d
54
55     def render_servermap(self, ctx, data):
56         d = self.upload_results()
57         d.addCallback(lambda res: res.servermap)
58         def _render(servermap):
59             if servermap is None:
60                 return "None"
61             l = T.ul()
62             for peerid in sorted(servermap.keys()):
63                 peerid_s = idlib.shortnodeid_b2a(peerid)
64                 shares_s = ",".join(["#%d" % shnum
65                                      for shnum in servermap[peerid]])
66                 l[T.li["[%s] got share%s: %s" % (peerid_s,
67                                                  plural(servermap[peerid]),
68                                                  shares_s)]]
69             return l
70         d.addCallback(_render)
71         return d
72
73     def data_file_size(self, ctx, data):
74         d = self.upload_results()
75         d.addCallback(lambda res: res.file_size)
76         return d
77
78     def _get_time(self, name):
79         d = self.upload_results()
80         d.addCallback(lambda res: res.timings.get(name))
81         return d
82
83     def data_time_total(self, ctx, data):
84         return self._get_time("total")
85
86     def data_time_storage_index(self, ctx, data):
87         return self._get_time("storage_index")
88
89     def data_time_contacting_helper(self, ctx, data):
90         return self._get_time("contacting_helper")
91
92     def data_time_existence_check(self, ctx, data):
93         return self._get_time("existence_check")
94
95     def data_time_cumulative_fetch(self, ctx, data):
96         return self._get_time("cumulative_fetch")
97
98     def data_time_helper_total(self, ctx, data):
99         return self._get_time("helper_total")
100
101     def data_time_peer_selection(self, ctx, data):
102         return self._get_time("peer_selection")
103
104     def data_time_total_encode_and_push(self, ctx, data):
105         return self._get_time("total_encode_and_push")
106
107     def data_time_cumulative_encoding(self, ctx, data):
108         return self._get_time("cumulative_encoding")
109
110     def data_time_cumulative_sending(self, ctx, data):
111         return self._get_time("cumulative_sending")
112
113     def data_time_hashes_and_close(self, ctx, data):
114         return self._get_time("hashes_and_close")
115
116     def _get_rate(self, name):
117         d = self.upload_results()
118         def _convert(r):
119             file_size = r.file_size
120             time = r.timings.get(name)
121             if time is None:
122                 return None
123             try:
124                 return 1.0 * file_size / time
125             except ZeroDivisionError:
126                 return None
127         d.addCallback(_convert)
128         return d
129
130     def data_rate_total(self, ctx, data):
131         return self._get_rate("total")
132
133     def data_rate_storage_index(self, ctx, data):
134         return self._get_rate("storage_index")
135
136     def data_rate_encode(self, ctx, data):
137         return self._get_rate("cumulative_encoding")
138
139     def data_rate_push(self, ctx, data):
140         return self._get_rate("cumulative_sending")
141
142     def data_rate_encode_and_push(self, ctx, data):
143         d = self.upload_results()
144         def _convert(r):
145             file_size = r.file_size
146             if file_size is None:
147                 return None
148             time1 = r.timings.get("cumulative_encoding")
149             if time1 is None:
150                 return None
151             time2 = r.timings.get("cumulative_sending")
152             if time2 is None:
153                 return None
154             try:
155                 return 1.0 * file_size / (time1+time2)
156             except ZeroDivisionError:
157                 return None
158         d.addCallback(_convert)
159         return d
160
161     def data_rate_ciphertext_fetch(self, ctx, data):
162         d = self.upload_results()
163         def _convert(r):
164             fetch_size = r.ciphertext_fetched
165             if fetch_size is None:
166                 return None
167             time = r.timings.get("cumulative_fetch")
168             if time is None:
169                 return None
170             try:
171                 return 1.0 * fetch_size / time
172             except ZeroDivisionError:
173                 return None
174         d.addCallback(_convert)
175         return d
176
177 class UploadStatusPage(UploadResultsRendererMixin, rend.Page):
178     docFactory = getxmlfile("upload-status.xhtml")
179
180     def __init__(self, data):
181         rend.Page.__init__(self, data)
182         self.upload_status = data
183
184     def upload_results(self):
185         return defer.maybeDeferred(self.upload_status.get_results)
186
187     def render_results(self, ctx, data):
188         d = self.upload_results()
189         def _got_results(results):
190             if results:
191                 return ctx.tag
192             return ""
193         d.addCallback(_got_results)
194         return d
195
196     def render_started(self, ctx, data):
197         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
198         started_s = time.strftime(TIME_FORMAT,
199                                   time.localtime(data.get_started()))
200         return started_s
201
202     def render_si(self, ctx, data):
203         si_s = base32.b2a_or_none(data.get_storage_index())
204         if si_s is None:
205             si_s = "(None)"
206         return si_s
207
208     def render_helper(self, ctx, data):
209         return {True: "Yes",
210                 False: "No"}[data.using_helper()]
211
212     def render_total_size(self, ctx, data):
213         size = data.get_size()
214         if size is None:
215             size = "(unknown)"
216         return size
217
218     def render_progress_hash(self, ctx, data):
219         progress = data.get_progress()[0]
220         # TODO: make an ascii-art bar
221         return "%.1f%%" % (100.0 * progress)
222
223     def render_progress_ciphertext(self, ctx, data):
224         progress = data.get_progress()[1]
225         # TODO: make an ascii-art bar
226         return "%.1f%%" % (100.0 * progress)
227
228     def render_progress_encode_push(self, ctx, data):
229         progress = data.get_progress()[2]
230         # TODO: make an ascii-art bar
231         return "%.1f%%" % (100.0 * progress)
232
233     def render_status(self, ctx, data):
234         return data.get_status()
235
236 class DownloadResultsRendererMixin(RateAndTimeMixin):
237     # this requires a method named 'download_results'
238
239     def render_servermap(self, ctx, data):
240         d = self.download_results()
241         d.addCallback(lambda res: res.servermap)
242         def _render(servermap):
243             if servermap is None:
244                 return "None"
245             l = T.ul()
246             for peerid in sorted(servermap.keys()):
247                 peerid_s = idlib.shortnodeid_b2a(peerid)
248                 shares_s = ",".join(["#%d" % shnum
249                                      for shnum in servermap[peerid]])
250                 l[T.li["[%s] has share%s: %s" % (peerid_s,
251                                                  plural(servermap[peerid]),
252                                                  shares_s)]]
253             return l
254         d.addCallback(_render)
255         return d
256
257     def render_servers_used(self, ctx, data):
258         d = self.download_results()
259         d.addCallback(lambda res: res.servers_used)
260         def _got(servers_used):
261             if not servers_used:
262                 return ""
263             peerids_s = ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
264                                    for peerid in servers_used])
265             return T.li["Servers Used: ", peerids_s]
266         d.addCallback(_got)
267         return d
268
269     def render_problems(self, ctx, data):
270         d = self.download_results()
271         d.addCallback(lambda res: res.server_problems)
272         def _got(server_problems):
273             if not server_problems:
274                 return ""
275             l = T.ul()
276             for peerid in sorted(server_problems.keys()):
277                 peerid_s = idlib.shortnodeid_b2a(peerid)
278                 l[T.li["[%s]: %s" % (peerid_s, server_problems[peerid])]]
279             return T.li["Server Problems:", l]
280         d.addCallback(_got)
281         return d
282
283     def data_file_size(self, ctx, data):
284         d = self.download_results()
285         d.addCallback(lambda res: res.file_size)
286         return d
287
288     def _get_time(self, name):
289         d = self.download_results()
290         d.addCallback(lambda res: res.timings.get(name))
291         return d
292
293     def data_time_total(self, ctx, data):
294         return self._get_time("total")
295
296     def data_time_peer_selection(self, ctx, data):
297         return self._get_time("peer_selection")
298
299     def data_time_uri_extension(self, ctx, data):
300         return self._get_time("uri_extension")
301
302     def data_time_hashtrees(self, ctx, data):
303         return self._get_time("hashtrees")
304
305     def data_time_segments(self, ctx, data):
306         return self._get_time("segments")
307
308     def data_time_cumulative_fetch(self, ctx, data):
309         return self._get_time("cumulative_fetch")
310
311     def data_time_cumulative_decode(self, ctx, data):
312         return self._get_time("cumulative_decode")
313
314     def data_time_cumulative_decrypt(self, ctx, data):
315         return self._get_time("cumulative_decrypt")
316
317     def _get_rate(self, name):
318         d = self.download_results()
319         def _convert(r):
320             file_size = r.file_size
321             time = r.timings.get(name)
322             if time is None:
323                 return None
324             try:
325                 return 1.0 * file_size / time
326             except ZeroDivisionError:
327                 return None
328         d.addCallback(_convert)
329         return d
330
331     def data_rate_total(self, ctx, data):
332         return self._get_rate("total")
333
334     def data_rate_segments(self, ctx, data):
335         return self._get_rate("segments")
336
337     def data_rate_fetch(self, ctx, data):
338         return self._get_rate("cumulative_fetch")
339
340     def data_rate_decode(self, ctx, data):
341         return self._get_rate("cumulative_decode")
342
343     def data_rate_decrypt(self, ctx, data):
344         return self._get_rate("cumulative_decrypt")
345
346     def render_server_timings(self, ctx, data):
347         d = self.download_results()
348         d.addCallback(lambda res: res.timings.get("fetch_per_server"))
349         def _render(per_server):
350             if per_server is None:
351                 return ""
352             l = T.ul()
353             for peerid in sorted(per_server.keys()):
354                 peerid_s = idlib.shortnodeid_b2a(peerid)
355                 times_s = ", ".join([self.render_time(None, t)
356                                      for t in per_server[peerid]])
357                 l[T.li["[%s]: %s" % (peerid_s, times_s)]]
358             return T.li["Per-Server Segment Fetch Response Times: ", l]
359         d.addCallback(_render)
360         return d
361
362 class DownloadStatusPage(DownloadResultsRendererMixin, rend.Page):
363     docFactory = getxmlfile("download-status.xhtml")
364
365     def __init__(self, data):
366         rend.Page.__init__(self, data)
367         self.download_status = data
368
369     def download_results(self):
370         return defer.maybeDeferred(self.download_status.get_results)
371
372     def render_results(self, ctx, data):
373         d = self.download_results()
374         def _got_results(results):
375             if results:
376                 return ctx.tag
377             return ""
378         d.addCallback(_got_results)
379         return d
380
381     def render_started(self, ctx, data):
382         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
383         started_s = time.strftime(TIME_FORMAT,
384                                   time.localtime(data.get_started()))
385         return started_s
386
387     def render_si(self, ctx, data):
388         si_s = base32.b2a_or_none(data.get_storage_index())
389         if si_s is None:
390             si_s = "(None)"
391         return si_s
392
393     def render_helper(self, ctx, data):
394         return {True: "Yes",
395                 False: "No"}[data.using_helper()]
396
397     def render_total_size(self, ctx, data):
398         size = data.get_size()
399         if size is None:
400             size = "(unknown)"
401         return size
402
403     def render_progress(self, ctx, data):
404         progress = data.get_progress()
405         # TODO: make an ascii-art bar
406         return "%.1f%%" % (100.0 * progress)
407
408     def render_status(self, ctx, data):
409         return data.get_status()
410
411 class RetrieveStatusPage(rend.Page, RateAndTimeMixin):
412     docFactory = getxmlfile("retrieve-status.xhtml")
413
414     def __init__(self, data):
415         rend.Page.__init__(self, data)
416         self.retrieve_status = data
417
418     def render_started(self, ctx, data):
419         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
420         started_s = time.strftime(TIME_FORMAT,
421                                   time.localtime(data.get_started()))
422         return started_s
423
424     def render_si(self, ctx, data):
425         si_s = base32.b2a_or_none(data.get_storage_index())
426         if si_s is None:
427             si_s = "(None)"
428         return si_s
429
430     def render_helper(self, ctx, data):
431         return {True: "Yes",
432                 False: "No"}[data.using_helper()]
433
434     def render_current_size(self, ctx, data):
435         size = data.get_size()
436         if size is None:
437             size = "(unknown)"
438         return size
439
440     def render_progress(self, ctx, data):
441         progress = data.get_progress()
442         # TODO: make an ascii-art bar
443         return "%.1f%%" % (100.0 * progress)
444
445     def render_status(self, ctx, data):
446         return data.get_status()
447
448     def render_encoding(self, ctx, data):
449         k, n = data.get_encoding()
450         return ctx.tag["Encoding: %s of %s" % (k, n)]
451
452     def render_search_distance(self, ctx, data):
453         d = data.get_search_distance()
454         return ctx.tag["Search Distance: %s peer%s" % (d, plural(d))]
455
456     def render_problems(self, ctx, data):
457         problems = data.problems
458         if not problems:
459             return ""
460         l = T.ul()
461         for peerid in sorted(problems.keys()):
462             peerid_s = idlib.shortnodeid_b2a(peerid)
463             l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
464         return ctx.tag["Server Problems:", l]
465
466     def _get_rate(self, data, name):
467         file_size = self.retrieve_status.get_size()
468         time = self.retrieve_status.timings.get(name)
469         if time is None or file_size is None:
470             return None
471         try:
472             return 1.0 * file_size / time
473         except ZeroDivisionError:
474             return None
475
476     def data_time_total(self, ctx, data):
477         return self.retrieve_status.timings.get("total")
478     def data_rate_total(self, ctx, data):
479         return self._get_rate(data, "total")
480
481     def data_time_peer_selection(self, ctx, data):
482         return self.retrieve_status.timings.get("peer_selection")
483
484     def data_time_fetch(self, ctx, data):
485         return self.retrieve_status.timings.get("fetch")
486     def data_rate_fetch(self, ctx, data):
487         return self._get_rate(data, "fetch")
488
489     def data_time_cumulative_verify(self, ctx, data):
490         return self.retrieve_status.timings.get("cumulative_verify")
491
492     def data_time_decode(self, ctx, data):
493         return self.retrieve_status.timings.get("decode")
494     def data_rate_decode(self, ctx, data):
495         return self._get_rate(data, "decode")
496
497     def data_time_decrypt(self, ctx, data):
498         return self.retrieve_status.timings.get("decrypt")
499     def data_rate_decrypt(self, ctx, data):
500         return self._get_rate(data, "decrypt")
501
502     def render_server_timings(self, ctx, data):
503         per_server = self.retrieve_status.timings.get("fetch_per_server")
504         if not per_server:
505             return ""
506         l = T.ul()
507         for peerid in sorted(per_server.keys()):
508             peerid_s = idlib.shortnodeid_b2a(peerid)
509             times_s = ", ".join([self.render_time(None, t)
510                                  for t in per_server[peerid]])
511             l[T.li["[%s]: %s" % (peerid_s, times_s)]]
512         return T.li["Per-Server Fetch Response Times: ", l]
513
514
515 class PublishStatusPage(rend.Page, RateAndTimeMixin):
516     docFactory = getxmlfile("publish-status.xhtml")
517
518     def __init__(self, data):
519         rend.Page.__init__(self, data)
520         self.publish_status = data
521
522     def render_started(self, ctx, data):
523         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
524         started_s = time.strftime(TIME_FORMAT,
525                                   time.localtime(data.get_started()))
526         return started_s
527
528     def render_si(self, ctx, data):
529         si_s = base32.b2a_or_none(data.get_storage_index())
530         if si_s is None:
531             si_s = "(None)"
532         return si_s
533
534     def render_helper(self, ctx, data):
535         return {True: "Yes",
536                 False: "No"}[data.using_helper()]
537
538     def render_current_size(self, ctx, data):
539         size = data.get_size()
540         if size is None:
541             size = "(unknown)"
542         return size
543
544     def render_progress(self, ctx, data):
545         progress = data.get_progress()
546         # TODO: make an ascii-art bar
547         return "%.1f%%" % (100.0 * progress)
548
549     def render_status(self, ctx, data):
550         return data.get_status()
551
552     def render_encoding(self, ctx, data):
553         k, n = data.get_encoding()
554         return ctx.tag["Encoding: %s of %s" % (k, n)]
555
556     def render_peers_queried(self, ctx, data):
557         return ctx.tag["Peers Queried: ", data.peers_queried]
558
559     def render_sharemap(self, ctx, data):
560         sharemap = data.sharemap
561         if sharemap is None:
562             return ctx.tag["None"]
563         l = T.ul()
564         for shnum in sorted(sharemap.keys()):
565             l[T.li["%d -> Placed on " % shnum,
566                    ", ".join(["[%s]" % idlib.shortnodeid_b2a(peerid)
567                               for (peerid,seqnum,root_hash)
568                               in sharemap[shnum]])]]
569         return ctx.tag["Sharemap:", l]
570
571     def render_problems(self, ctx, data):
572         problems = data.problems
573         if not problems:
574             return ""
575         l = T.ul()
576         for peerid in sorted(problems.keys()):
577             peerid_s = idlib.shortnodeid_b2a(peerid)
578             l[T.li["[%s]: %s" % (peerid_s, problems[peerid])]]
579         return ctx.tag["Server Problems:", l]
580
581     def _get_rate(self, data, name):
582         file_size = self.publish_status.get_size()
583         time = self.publish_status.timings.get(name)
584         if time is None:
585             return None
586         try:
587             return 1.0 * file_size / time
588         except ZeroDivisionError:
589             return None
590
591     def data_time_total(self, ctx, data):
592         return self.publish_status.timings.get("total")
593     def data_rate_total(self, ctx, data):
594         return self._get_rate(data, "total")
595
596     def data_time_setup(self, ctx, data):
597         return self.publish_status.timings.get("setup")
598
599     def data_time_query(self, ctx, data):
600         return self.publish_status.timings.get("query")
601
602     def data_time_privkey(self, ctx, data):
603         return self.publish_status.timings.get("privkey")
604
605     def data_time_privkey_fetch(self, ctx, data):
606         return self.publish_status.timings.get("privkey_fetch")
607     def render_privkey_from(self, ctx, data):
608         peerid = data.privkey_from
609         if peerid:
610             return " (got from [%s])" % idlib.shortnodeid_b2a(peerid)
611         else:
612             return ""
613
614     def data_time_encrypt(self, ctx, data):
615         return self.publish_status.timings.get("encrypt")
616     def data_rate_encrypt(self, ctx, data):
617         return self._get_rate(data, "encrypt")
618
619     def data_time_encode(self, ctx, data):
620         return self.publish_status.timings.get("encode")
621     def data_rate_encode(self, ctx, data):
622         return self._get_rate(data, "encode")
623
624     def data_time_pack(self, ctx, data):
625         return self.publish_status.timings.get("pack")
626     def data_rate_pack(self, ctx, data):
627         return self._get_rate(data, "pack")
628     def data_time_sign(self, ctx, data):
629         return self.publish_status.timings.get("sign")
630
631     def data_time_push(self, ctx, data):
632         return self.publish_status.timings.get("push")
633     def data_rate_push(self, ctx, data):
634         return self._get_rate(data, "push")
635
636     def data_initial_read_size(self, ctx, data):
637         return self.publish_status.initial_read_size
638
639     def render_server_timings(self, ctx, data):
640         per_server = self.publish_status.timings.get("per_server")
641         if not per_server:
642             return ""
643         l = T.ul()
644         for peerid in sorted(per_server.keys()):
645             peerid_s = idlib.shortnodeid_b2a(peerid)
646             times = []
647             for op,t in per_server[peerid]:
648                 if op == "read":
649                     times.append( "(" + self.render_time(None, t) + ")" )
650                 else:
651                     times.append( self.render_time(None, t) )
652             times_s = ", ".join(times)
653             l[T.li["[%s]: %s" % (peerid_s, times_s)]]
654         return T.li["Per-Server Response Times: ", l]
655
656
657 class Status(rend.Page):
658     docFactory = getxmlfile("status.xhtml")
659     addSlash = True
660
661     def data_active_operations(self, ctx, data):
662         active =  (IClient(ctx).list_active_uploads() +
663                    IClient(ctx).list_active_downloads() +
664                    IClient(ctx).list_active_publish() +
665                    IClient(ctx).list_active_retrieve())
666         return active
667
668     def data_recent_operations(self, ctx, data):
669         recent = [o for o in (IClient(ctx).list_recent_uploads() +
670                               IClient(ctx).list_recent_downloads() +
671                               IClient(ctx).list_recent_publish() +
672                               IClient(ctx).list_recent_retrieve())
673                   if not o.get_active()]
674         recent.sort(lambda a,b: cmp(a.get_started(), b.get_started()))
675         recent.reverse()
676         return recent
677
678     def render_row(self, ctx, data):
679         s = data
680
681         TIME_FORMAT = "%H:%M:%S %d-%b-%Y"
682         started_s = time.strftime(TIME_FORMAT,
683                                   time.localtime(s.get_started()))
684         ctx.fillSlots("started", started_s)
685
686         si_s = base32.b2a_or_none(s.get_storage_index())
687         if si_s is None:
688             si_s = "(None)"
689         ctx.fillSlots("si", si_s)
690         ctx.fillSlots("helper", {True: "Yes",
691                                  False: "No"}[s.using_helper()])
692
693         size = s.get_size()
694         if size is None:
695             size = "(unknown)"
696         ctx.fillSlots("total_size", size)
697
698         progress = data.get_progress()
699         if IUploadStatus.providedBy(data):
700             link = "up-%d" % data.get_counter()
701             ctx.fillSlots("type", "upload")
702             # TODO: make an ascii-art bar
703             (chk, ciphertext, encandpush) = progress
704             progress_s = ("hash: %.1f%%, ciphertext: %.1f%%, encode: %.1f%%" %
705                           ( (100.0 * chk),
706                             (100.0 * ciphertext),
707                             (100.0 * encandpush) ))
708             ctx.fillSlots("progress", progress_s)
709         elif IDownloadStatus.providedBy(data):
710             link = "down-%d" % data.get_counter()
711             ctx.fillSlots("type", "download")
712             ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
713         elif IPublishStatus.providedBy(data):
714             link = "publish-%d" % data.get_counter()
715             ctx.fillSlots("type", "publish")
716             ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
717         else:
718             assert IRetrieveStatus.providedBy(data)
719             ctx.fillSlots("type", "retrieve")
720             link = "retrieve-%d" % data.get_counter()
721             ctx.fillSlots("progress", "%.1f%%" % (100.0 * progress))
722         ctx.fillSlots("status", T.a(href=link)[s.get_status()])
723         return ctx.tag
724
725     def childFactory(self, ctx, name):
726         client = IClient(ctx)
727         stype,count_s = name.split("-")
728         count = int(count_s)
729         if stype == "up":
730             for s in client.list_recent_uploads():
731                 if s.get_counter() == count:
732                     return UploadStatusPage(s)
733             for u in client.list_all_uploads():
734                 # u is an uploader object
735                 s = u.get_upload_status()
736                 if s.get_counter() == count:
737                     return UploadStatusPage(s)
738         if stype == "down":
739             for s in client.list_recent_downloads():
740                 if s.get_counter() == count:
741                     return DownloadStatusPage(s)
742             for d in client.list_all_downloads():
743                 s = d.get_download_status()
744                 if s.get_counter() == count:
745                     return DownloadStatusPage(s)
746         if stype == "publish":
747             for s in client.list_recent_publish():
748                 if s.get_counter() == count:
749                     return PublishStatusPage(s)
750             for p in client.list_all_publish():
751                 s = p.get_status()
752                 if s.get_counter() == count:
753                     return PublishStatusPage(s)
754         if stype == "retrieve":
755             for s in client.list_recent_retrieve():
756                 if s.get_counter() == count:
757                     return RetrieveStatusPage(s)
758             for r in client.list_all_retrieve():
759                 s = r.get_status()
760                 if s.get_counter() == count:
761                     return RetrieveStatusPage(s)
762
763
764 class HelperStatus(rend.Page):
765     docFactory = getxmlfile("helper.xhtml")
766
767     def renderHTTP(self, ctx):
768         t = get_arg(inevow.IRequest(ctx), "t")
769         if t == "json":
770             return self.render_JSON(ctx)
771         # is there a better way to provide 'data' to all rendering methods?
772         helper = IClient(ctx).getServiceNamed("helper")
773         self.original = helper.get_stats()
774         return rend.Page.renderHTTP(self, ctx)
775
776     def render_JSON(self, ctx):
777         try:
778             h = IClient(ctx).getServiceNamed("helper")
779         except KeyError:
780             return simplejson.dumps({})
781
782         stats = h.get_stats()
783         return simplejson.dumps(stats, indent=1)
784
785     def render_active_uploads(self, ctx, data):
786         return data["chk_upload_helper.active_uploads"]
787
788     def render_incoming(self, ctx, data):
789         return "%d bytes in %d files" % (data["chk_upload_helper.incoming_size"],
790                                          data["chk_upload_helper.incoming_count"])
791
792     def render_encoding(self, ctx, data):
793         return "%d bytes in %d files" % (data["chk_upload_helper.encoding_size"],
794                                          data["chk_upload_helper.encoding_count"])
795
796     def render_upload_requests(self, ctx, data):
797         return str(data["chk_upload_helper.upload_requests"])
798
799     def render_upload_already_present(self, ctx, data):
800         return str(data["chk_upload_helper.upload_already_present"])
801
802     def render_upload_need_upload(self, ctx, data):
803         return str(data["chk_upload_helper.upload_need_upload"])
804
805     def render_upload_bytes_fetched(self, ctx, data):
806         return str(data["chk_upload_helper.fetched_bytes"])
807
808     def render_upload_bytes_encoded(self, ctx, data):
809         return str(data["chk_upload_helper.encoded_bytes"])
810