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.
This commit is contained in:
Brian Warner 2007-10-30 17:00:37 -07:00
parent 9b92bff51c
commit b257f905a0

View File

@ -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