From: Brian Warner Date: Wed, 31 Oct 2007 00:00:37 +0000 (-0700) Subject: webish.py: handle asynchronous checker results. X-Git-Tag: allmydata-tahoe-0.7.0~346 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/biz?a=commitdiff_plain;h=b257f905a0595de21052cba82c7dd22c8f5d45e2;p=tahoe-lafs%2Ftahoe-lafs.git webish.py: handle asynchronous checker results. Thanks to robk for pointing out that Nevow will accept a Deferred almost everywhere. In this case, we just pass a Deferred into ctx.fillSlots(). One quirk: nevow doesn't evaluate all rows of the table in parallel: using a slow Deferred in a slot in one row seems to stall the next row until that one has fired, probably to simplify the flattening of the HTML. --- diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index ecde7f67..d7e07299 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -232,24 +232,31 @@ class Directory(rend.Page): except KeyError: checker = None if checker: - checker_results = checker.checker_results_for(target.get_verifier()) - recent_results = reversed(checker_results[-5:]) - if IFileNode.providedBy(target): - results = ("[" + - ", ".join(["%d/%d" % (found, needed) - for (when, - (needed, total, found, sharemap)) - in recent_results]) + - "]") - elif IDirectoryNode.providedBy(target): - results = ("[" + - "".join([{True:"+",False:"-"}[res] - for (when, res) in recent_results]) + - "]") - else: - results = "%d results" % len(checker_results) + d = defer.maybeDeferred(checker.checker_results_for, + target.get_verifier()) + def _got(checker_results): + recent_results = reversed(checker_results[-5:]) + if IFileNode.providedBy(target): + results = ("[" + + ", ".join(["%d/%d" % (found, needed) + for (when, + (needed, total, found, sharemap)) + in recent_results]) + + "]") + elif IDirectoryNode.providedBy(target): + results = ("[" + + "".join([{True:"+",False:"-"}[res] + for (when, res) in recent_results]) + + "]") + else: + results = "%d results" % len(checker_results) + return results + d.addCallback(_got) + results = d else: results = "--" + # TODO: include a link to see more results, including timestamps + # TODO: use a sparkline ctx.fillSlots("checker_results", results) return ctx.tag