commit 687a6ffdf9e2fabfeb8711cbbd085d0378fb7a9e
Author: Arturo Filastò <art(a)fuffa.org>
Date: Fri Dec 4 17:44:04 2015 +0100
Start adding support for not reporting to file on disk
---
ooni/director.py | 5 +++--
ooni/nettest.py | 1 +
ooni/oonicli.py | 11 ++++++++---
ooni/reporter.py | 38 ++++++++++++++++++++++++--------------
4 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/ooni/director.py b/ooni/director.py
index f633048..4aa5fba 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -233,7 +233,7 @@ class Director(object):
@defer.inlineCallbacks
def startNetTest(self, net_test_loader, report_filename,
- collector_address=None):
+ collector_address=None, no_yamloo=False):
"""
Create the Report for the NetTest and start the report NetTest.
@@ -248,7 +248,8 @@ class Director(object):
self.startSniffing(net_test_loader.testDetails)
report = Report(net_test_loader.testDetails, report_filename,
- self.reportEntryManager, collector_address)
+ self.reportEntryManager, collector_address,
+ no_yamloo)
net_test = NetTest(net_test_loader, report)
net_test.director = self
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 848d958..5207b8a 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -131,6 +131,7 @@ def getNetTestInformation(net_test_file):
class NetTestLoader(object):
method_prefix = 'test'
collector = None
+ yamloo = True
requiresTor = False
reportID = None
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index d75aa41..b9133c9 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -34,7 +34,8 @@ class Options(usage.Options):
optFlags = [["help", "h"],
["resume", "r"],
- ["no-collector", "n"],
+ ["no-collector", "n", "disable writing to collector"],
+ ["no-yamloo", "N", "disable writing to YAML file"],
["no-geoip", "g"],
["list", "s"],
["printdeck", "p"],
@@ -228,6 +229,9 @@ def setupCollector(global_options, net_test_loader):
def createDeck(global_options, url=None):
log.msg("Creating deck for: %s" % (url))
+ if global_options['no-yamloo']:
+ log.msg("Will not write to a yamloo report file")
+
deck = Deck(no_collector=global_options['no-collector'])
deck.bouncer = global_options['bouncer']
@@ -316,8 +320,9 @@ def runTestWithDirector(director, global_options, url=None,
net_test_loader.annotations = global_options['annotations']
director.startNetTest(net_test_loader,
- global_options['reportfile'],
- collector)
+ global_options['reportfile'],
+ collector,
+ global_options['no-yamloo'])
return director.allTestsDone
d.addCallback(setup_nettest)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index a8272f5..db6f7c1 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -554,7 +554,8 @@ class OONIBReportLog(object):
class Report(object):
def __init__(self, test_details, report_filename,
- reportEntryManager, collector_address=None):
+ reportEntryManager, collector_address=None,
+ no_yamloo=False):
"""
This is an abstraction layer on top of all the configured reporters.
@@ -574,14 +575,19 @@ class Report(object):
collector:
The address of the oonib collector for this report.
+ no_yamloo:
+ If we should disable reporting to disk.
"""
self.test_details = test_details
self.collector_address = collector_address
self.report_log = OONIBReportLog()
- self.yaml_reporter = YAMLReporter(test_details, report_filename=report_filename)
- self.report_filename = self.yaml_reporter.report_path
+ self.yaml_reporter = None
+ self.report_filename = None
+ if not no_yamloo:
+ self.yaml_reporter = YAMLReporter(test_details, report_filename=report_filename)
+ self.report_filename = self.yaml_reporter.report_path
self.oonib_reporter = None
if collector_address:
@@ -627,11 +633,13 @@ class Report(object):
if self.oonib_reporter:
deferreds.append(self.open_oonib_reporter())
else:
- deferreds.append(self.report_log.not_created(self.report_filename))
+ if self.yaml_reporter:
+ deferreds.append(self.report_log.not_created(self.report_filename))
- yaml_report_created = \
- defer.maybeDeferred(self.yaml_reporter.createReport)
- yaml_report_created.addErrback(yaml_report_failed)
+ if self.yaml_reporter:
+ yaml_report_created = \
+ defer.maybeDeferred(self.yaml_reporter.createReport)
+ yaml_report_created.addErrback(yaml_report_failed)
dl = defer.DeferredList(deferreds)
dl.addCallback(all_reports_openned)
@@ -666,10 +674,11 @@ class Report(object):
if not d.called:
d.callback(None)
- write_yaml_report = ReportEntry(self.yaml_reporter, measurement)
- self.reportEntryManager.schedule(write_yaml_report)
- write_yaml_report.done.addErrback(yaml_report_failed)
- deferreds.append(write_yaml_report.done)
+ if self.yaml_reporter:
+ write_yaml_report = ReportEntry(self.yaml_reporter, measurement)
+ self.reportEntryManager.schedule(write_yaml_report)
+ write_yaml_report.done.addErrback(yaml_report_failed)
+ deferreds.append(write_yaml_report.done)
if self.oonib_reporter:
write_oonib_report = ReportEntry(self.oonib_reporter, measurement)
@@ -707,9 +716,10 @@ class Report(object):
if not d.called:
d.callback(None)
- close_yaml = defer.maybeDeferred(self.yaml_reporter.finish)
- close_yaml.addErrback(yaml_report_failed)
- deferreds.append(close_yaml)
+ if self.yaml_reporter:
+ close_yaml = defer.maybeDeferred(self.yaml_reporter.finish)
+ close_yaml.addErrback(yaml_report_failed)
+ deferreds.append(close_yaml)
if self.oonib_reporter:
close_oonib = self.oonib_reporter.finish()