[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Join ooniprobe and ooniprobequeue into one command
commit 1192ca0d0fd7c7b4aa5cb593fe711eb175d5c880
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date: Tue Apr 26 23:33:14 2016 +0200
Join ooniprobe and ooniprobequeue into one command
---
bin/ooniprobe | 19 +++++++++++++++++--
bin/ooniprobequeue | 16 ----------------
ooni/oonicli.py | 21 +++++++--------------
ooni/tests/test_oonicli.py | 5 +++--
setup.py | 3 +--
5 files changed, 28 insertions(+), 36 deletions(-)
diff --git a/bin/ooniprobe b/bin/ooniprobe
index 4832d91..ad97553 100755
--- a/bin/ooniprobe
+++ b/bin/ooniprobe
@@ -1,9 +1,24 @@
#!/usr/bin/env python
+import sys
+
from twisted.internet import reactor
-from ooni.oonicli import runWithDirector
-d = runWithDirector()
+from ooni.oonicli import setupGlobalOptions
+from ooni.oonicli import runWithDaemonDirector, runWithDirector
+
+exit_code=0
+
+global_options = setupGlobalOptions(logging=True, start_tor=True,
+ check_incoherences=True)
+if global_options['queue']:
+ d = runWithDaemonDirector(global_options)
+else:
+ d = runWithDirector(global_options)
@d.addBoth
def cb(result):
+ global exit_code
+ if result is not None:
+ exit_code=1
reactor.stop()
reactor.run()
+sys.exit(exit_code)
diff --git a/bin/ooniprobequeue b/bin/ooniprobequeue
deleted file mode 100755
index 88359e0..0000000
--- a/bin/ooniprobequeue
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env python
-import sys
-from twisted.internet import reactor
-
-code=0
-
-from ooni.oonicli import runWithDaemonDirector
-d = runWithDaemonDirector()
-@xxxxxxxxx
-def cb(result):
- global code
- if result is not None:
- code=1
- reactor.stop()
-reactor.run()
-sys.exit(code)
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 09936b6..1ffe467 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -205,6 +205,7 @@ def setupGlobalOptions(logging, start_tor, check_incoherences):
log.err("Insufficient Privileges to capture packets."
" See ooniprobe.conf privacy.includepcap")
sys.exit(2)
+ global_options['check_incoherences'] = check_incoherences
return global_options
def setupAnnotations(global_options):
@@ -294,14 +295,13 @@ def createDeck(global_options, url=None):
return deck
-def runTestWithDirector(director, global_options, url=None,
- start_tor=True, check_incoherences=True):
+def runTestWithDirector(director, global_options, url=None, start_tor=True):
deck = createDeck(global_options, url=url)
start_tor |= deck.requiresTor
d = director.start(start_tor=start_tor,
- check_incoherences=check_incoherences)
+ check_incoherences=global_options['check_incoherences'])
def setup_nettest(_):
try:
@@ -341,13 +341,11 @@ def runTestWithDirector(director, global_options, url=None,
d.addErrback(director_startup_other_failures)
return d
-def runWithDirector(logging=True, start_tor=True, check_incoherences=True):
+def runWithDirector(global_options):
"""
Instance the director, parse command line options and start an ooniprobe
test!
"""
- global_options = setupGlobalOptions(logging, start_tor, check_incoherences)
-
from ooni.director import Director
director = Director()
if global_options['list']:
@@ -398,14 +396,13 @@ def runWithDirector(logging=True, start_tor=True, check_incoherences=True):
return runTestWithDirector(director=director,
start_tor=start_tor,
- global_options=global_options,
- check_incoherences=check_incoherences)
+ global_options=global_options)
# this variant version of runWithDirector splits the process in two,
# allowing a single director instance to be reused with multiple decks.
-def runWithDaemonDirector(logging=True, start_tor=True, check_incoherences=True):
+def runWithDaemonDirector(global_options):
"""
Instance the director, parse command line options and start an ooniprobe
test!
@@ -421,9 +418,6 @@ def runWithDaemonDirector(logging=True, start_tor=True, check_incoherences=True)
print "Install with \"pip install pika\"."
sys.exit(7)
-
- global_options = setupGlobalOptions(logging, start_tor, check_incoherences)
-
director = Director()
if global_options.get('annotations') is not None:
@@ -464,8 +458,7 @@ def runWithDaemonDirector(logging=True, start_tor=True, check_incoherences=True)
d = runTestWithDirector(director=director,
start_tor=start_tor,
global_options=global_options,
- url=data['url'].encode('utf8'),
- check_incoherences=check_incoherences)
+ url=data['url'].encode('utf8'))
# When the test has been completed, go back to waiting for a message.
d.addCallback(readmsg, channel, queue_object, consumer_tag, counter+1)
except exceptions.AMQPError,v:
diff --git a/ooni/tests/test_oonicli.py b/ooni/tests/test_oonicli.py
index 172b9cd..f5c8545 100644
--- a/ooni/tests/test_oonicli.py
+++ b/ooni/tests/test_oonicli.py
@@ -7,7 +7,7 @@ from twisted.internet import defer
from ooni.tests import is_internet_connected
from ooni.tests.bases import ConfigTestCase
from ooni.settings import config
-from ooni.oonicli import runWithDirector
+from ooni.oonicli import runWithDirector, setupGlobalOptions
from ooni.utils.net import hasRawSocketPermission
@@ -89,7 +89,8 @@ class TestRunDirector(ConfigTestCase):
sys.argv.extend(ooni_args)
sys.argv.extend(['-n', '-o', output_file, test_name])
sys.argv.extend(nettest_args)
- yield runWithDirector(False, False, False)
+ global_options = setupGlobalOptions(False, False, False)
+ yield runWithDirector(global_options)
with open(output_file) as f:
entries = yaml.safe_load_all(f)
header = entries.next()
diff --git a/setup.py b/setup.py
index 1fd9a7b..a70df0c 100644
--- a/setup.py
+++ b/setup.py
@@ -204,8 +204,7 @@ setup(
packages=packages,
include_package_data=True,
scripts=["bin/oonideckgen", "bin/ooniprobe",
- "bin/oonireport", "bin/ooniresources",
- "bin/ooniprobequeue"],
+ "bin/oonireport", "bin/ooniresources"],
dependency_links=dependency_links,
install_requires=install_requires,
zip_safe=False,
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits