[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Add option to disable the default collector



commit 9a30d020ce6bbfdbfc3e56dcc2b89cb932bfdb6f
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sat Mar 9 03:13:50 2013 +0100

    Add option to disable the default collector
    
    * More robust startup process
---
 ooni/errors.py  |    2 ++
 ooni/oonicli.py |   36 ++++++++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/ooni/errors.py b/ooni/errors.py
index ac05463..1be42c3 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -147,3 +147,5 @@ class GeoIPDataFilesNotFound(Exception):
     pass
 class NoMoreReporters(Exception):
     pass
+class TorNotRunning(Exception):
+    pass
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 06aa20c..3eae499 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -10,7 +10,7 @@ from twisted.internet import reactor
 from twisted.python import usage
 from twisted.python.util import spewer
 
-from ooni.errors import InvalidOONIBCollectorAddress
+from ooni import errors
 
 from ooni import config
 from ooni.director import Director
@@ -29,7 +29,9 @@ class Options(usage.Options):
                 " files listed on the command line")
 
     optFlags = [["help", "h"],
-                ["resume", "r"]]
+                ["resume", "r"],
+                ["no-collector", "n"]
+                ]
 
     optParameters = [["reportfile", "o", None, "report file name"],
                      ["testdeck", "i", None,
@@ -102,6 +104,9 @@ def runWithDirector():
 
     # contains (test_cases, options, cmd_line_options)
     test_list = []
+    if global_options['no-collector']:
+        log.msg("Not reporting using a collector")
+        global_options.pop('collector')
 
     if global_options['testdeck']:
         test_deck = yaml.safe_load(open(global_options['testdeck']))
@@ -131,32 +136,43 @@ def runWithDirector():
 
     def director_startup_failed(failure):
         log.err("Failed to start the director")
-        log.exception(failure)
         reactor.stop()
 
     # Wait until director has started up (including bootstrapping Tor) before adding tess
     def post_director_start(_):
         for net_test_loader in test_list:
+            collector = global_options['collector']
             test_details = net_test_loader.testDetails
 
             yaml_reporter = YAMLReporter(test_details)
             reporters = [yaml_reporter]
 
-            if global_options['collector']:
+            if collector.startswith('httpo') \
+                    and not config.tor_state:
+                log.err("Tor does not appear to be running")
+                log.err("Reporting with the collector %s is not possible")
+                log.msg("Try with a different collector or disable collector reporting with -n")
+                raise errors.TorNotRunning
+            elif collector:
+                log.msg("Reporting using collector: %s" %
+                        collector)
                 try:
                     oonib_reporter = OONIBReporter(test_details,
-                            global_options['collector'])
+                            collector)
                     reporters.append(oonib_reporter)
-                except InvalidOONIBCollectorAddress:
+                except errors.InvalidOONIBCollectorAddress, e:
                     log.err("Invalid format for oonib collector address.")
                     log.msg("Should be in the format http://<collector_address>:<port>")
                     log.msg("for example: ooniprobe -c httpo://nkvphnp3p6agi5qq.onion")
-                    sys.exit(1)
+                    raise e
 
             log.debug("adding callback for startNetTest")
             d.addCallback(director.startNetTest, net_test_loader, reporters)
-        d.addCallback(shutdown)
+        d.addBoth(shutdown)
 
-    d.addCallback(post_director_start)
-    d.addErrback(director_startup_failed)
+    def start():
+        d.addCallback(post_director_start)
+        d.addErrback(director_startup_failed)
+
+    reactor.callWhenRunning(start)
     reactor.run()



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits