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

[tor-commits] [ooni-probe/master] Add config file parsing support to oonireport



commit ec7a5291e31cb7d3bd0a1457fdef62085436b61b
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Wed Jan 21 14:10:56 2015 +0100

    Add config file parsing support to oonireport
    
    Properly pass error codes onward
---
 bin/oonireport     |   19 +++++++++++++++++--
 ooni/report/cli.py |    6 +++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/bin/oonireport b/bin/oonireport
index 3a06b3b..84fc80d 100755
--- a/bin/oonireport
+++ b/bin/oonireport
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 import os
 import sys
+import exceptions
 
 sys.path[:] = map(os.path.abspath, sys.path)
 sys.path.insert(0, os.path.abspath(os.getcwd()))
@@ -10,12 +11,25 @@ from twisted.internet import defer, reactor
 from ooni.utils import log
 from ooni.report import cli
 
+exitCode = 128
+
 def failed(failure):
-    log.err("Failed to run ooni-report")
-    log.exception(failure)
+    global exitCode
+
+    r = failure.trap(exceptions.SystemExit)
+    if r != exceptions.SystemExit:
+        log.err("Failed to run oonideckgen")
+        log.exception(failure)
+        exitCode = 127
+    else:
+        exitCode = failure.value.code
     reactor.stop()
 
+
 def done(result):
+    global exitCode
+    exitCode = 0
+
     reactor.stop()
 
 def start():
@@ -25,3 +39,4 @@ def start():
 
 reactor.callWhenRunning(start)
 reactor.run()
+sys.exit(exitCode)
diff --git a/ooni/report/cli.py b/ooni/report/cli.py
index 2523c4f..e52b022 100644
--- a/ooni/report/cli.py
+++ b/ooni/report/cli.py
@@ -16,6 +16,8 @@ class Options(usage.Options):
 """ % (os.path.basename(sys.argv[0]),)
 
     optParameters = [
+        ["configfile", "f", None,
+         "Specify the configuration file to use."],
         ["collector", "c", None,
          "Specify the collector to upload the result to."],
         ["bouncer", "b", None,
@@ -52,7 +54,6 @@ def tor_check():
 
 
 def run():
-    config.read_config_file()
     options = Options()
     try:
         options.parseOptions()
@@ -60,6 +61,9 @@ def run():
         print("Error: %s" % exc)
         print(options)
         sys.exit(2)
+    config.global_options = dict(options)
+    config.set_paths()
+    config.read_config_file()
     if options['command'] == "upload" and options['report_file']:
         tor_check()
         return tool.upload(options['report_file'],



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