commit 12fd780b9f00b2c016db8cda8fe24f8a5d1cd007 Author: aagbsn aagbsn@extc.org Date: Wed Sep 18 13:41:48 2013 +0200
Fix ambiguity in what a ReportEntryTask does
ReportEntryTask can be passed dicts, Measurements, or Failures --- ooni/reporter.py | 16 ++++++++++++---- ooni/tasks.py | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py index b5fcce8..72c6975 100644 --- a/ooni/reporter.py +++ b/ooni/reporter.py @@ -19,7 +19,7 @@ from twisted.internet.error import ConnectionRefusedError from twisted.python.failure import Failure
from ooni.utils import log - +from ooni.tasks import Measurement try: from scapy.packet import Packet except ImportError: @@ -202,9 +202,11 @@ class YAMLReporter(OReporter): def writeReportEntry(self, entry): log.debug("Writing report with YAML reporter") self._write('---\n') - if isinstance(entry, Failure): + if isinstance(entry, Measurement): + self._write(safe_dump(entry.testInstance.report)) + elif isinstance(entry, Failure): self._write(entry.value) - else: + elif isinstance(entry, dict): self._write(safe_dump(entry)) self._write('...\n')
@@ -255,7 +257,12 @@ class OONIBReporter(OReporter): def writeReportEntry(self, entry): log.debug("Writing report with OONIB reporter") content = '---\n' - content += safe_dump(entry) + if isinstance(entry, Measurement): + content += safe_dump(entry.testInstance.report) + elif isinstance(entry, Failure): + content += entry.value + elif isinstance(entry, dict): + content += safe_dump(entry) content += '...\n'
url = self.collectorAddress + '/report' @@ -444,6 +451,7 @@ class Report(object): a deferred that will fire once all the report entries have been written or errbacks when no more reporters """ + all_written = defer.Deferred() report_tracker = ReportTracker(self.reporters)
diff --git a/ooni/tasks.py b/ooni/tasks.py index baefb51..3007a11 100644 --- a/ooni/tasks.py +++ b/ooni/tasks.py @@ -154,13 +154,13 @@ class ReportTracker(object): self.report_completed += 1
class ReportEntry(TaskWithTimeout): - def __init__(self, reporter, measurement): + def __init__(self, reporter, entry): self.reporter = reporter - self.measurement = measurement + self.entry = entry
if config.advanced.reporting_timeout: self.timeout = config.advanced.reporting_timeout TaskWithTimeout.__init__(self)
def run(self): - return self.reporter.writeReportEntry(self.measurement) + return self.reporter.writeReportEntry(self.entry)
tor-commits@lists.torproject.org