[tor-commits] [ooni-probe/master] * Moved /bin/ooniprobe start script to /bin/oonicli.

isis at torproject.org isis at torproject.org
Fri Oct 12 00:09:08 UTC 2012


commit 16983944cdb94a9dee09a377e000d5b23b5ac322
Author: Isis Lovecruft <isis at torproject.org>
Date:   Sat Oct 6 23:10:22 2012 +0000

    * Moved /bin/ooniprobe start script to /bin/oonicli.
    * Added new /bin/ooniprobe start script to use the old ooniprobe.py for
      legacy tests.
    * Fixed a bug in ooniprobe.runTest where it returned too early.
    * Fixed the inputs parser in ooni.runner.adaptLegacyTest.
---
 bin/oonicli       |   28 ++++++++++++++++
 bin/ooniprobe     |   89 +++++++++++++++++++++++++++++++++++++++++++---------
 ooni/ooniprobe.py |    7 ++--
 ooni/runner.py    |    1 -
 4 files changed, 105 insertions(+), 20 deletions(-)

diff --git a/bin/oonicli b/bin/oonicli
new file mode 100755
index 0000000..1e73c85
--- /dev/null
+++ b/bin/oonicli
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+###############################################################################
+#
+# oonicli
+# -----------------------
+#
+# Run the Twisted Trial (unittest module) based oonicli. Startup script based 
+# on twisted trial, see http://twistedmatrix.com/ .
+#
+# :authors: Arturo Filastò
+# :licence: see included LICENSE file
+# :version: 0.0.1-pre-alpha
+###############################################################################
+
+import os, sys
+import copy_reg
+
+# Hack to set the proper sys.path. Overcomes the export PYTHONPATH pain.
+sys.path[:] = map(os.path.abspath, sys.path)
+sys.path.insert(0, os.path.abspath(os.getcwd()))
+
+# This is a hack to overcome a bug in python
+from ooni.utils.hacks import patched_reduce_ex
+copy_reg._reduce_ex = patched_reduce_ex
+
+from ooni.oonicli import run
+run()
diff --git a/bin/ooniprobe b/bin/ooniprobe
index 4e400ce..e234587 100755
--- a/bin/ooniprobe
+++ b/bin/ooniprobe
@@ -1,23 +1,80 @@
-#!/usr/bin/env python
-# -*- encoding: utf-8 -*-
+#!/bin/bash
+##############################################################################
 #
-# startup script based on twisted trial
-# See http://twistedmatrix.com/
+# ooniprobe
+# -------------------
+# Setup environment variables and launch /ooni/ooniprobe.py without 
+# installing.
 #
-# :authors: Arturo Filastò
-# :licence: see LICENSE
+#-----------------------------------------------------------------------------
+# :authors: Isis Lovecruft, Arturo Filasto
+# :license: see included LICENSE file
+# :version: 0.0.1-pre-alpha
+#
+##############################################################################
+
+OONI_EXEC="ooniprobe.py"
+#OONI_EXEC="oonicli.py"
+OONI_PROCESS_NAME=$(echo $OONI_EXEC | sed s/\.py//)
+
+OONI_SCRIPT_IS_HERE=$(dirname ${BASH_SOURCE[0]})
+OONI_BIN="$(cd $OONI_SCRIPT_IS_HERE && pwd)"
+OONI_REPO="$(cd $OONI_BIN"/.." && pwd)"
+OONI_DIR="$OONI_REPO/ooni"
+
+OONI_PATH_ALREADY_SET=false
+
+function usage() {
+    echo "$0 - A simple wrapper around ooniprobe and oonicli to set"
+    echo "up environment variables, so that it can be run without installation."
+    echo;
+    echo "Usage: $0 [oonitest || file || script] [options]"
+    echo "All options and parameters are passed directly to ooniprobe, do"
+    echo "ooniprobe.py --help to see more."
+    echo;
+}
 
+function check_pythonpath_for_ooni() {
+    pythonpaths="$(echo $PYTHONPATH | cut -d ':' -f '1-' --output-delimiter=' ')"
+    for dir in $pythonpaths; do
+        if [[ "x$dir" == "x$OONI_REPO" ]]; then
+            export OONI_PATH_ALREADY_SET=true
+        else
+            continue
+        fi
+    done
+}
 
-import os, sys
-import copy_reg
+function add_ooni_to_pythonpath() {
+    if test ! $OONI_PATH_ALREADY_SET ; then
+        echo "Appending $OONI_REPO to PYTHONPATH..."
+        export PYTHONPATH=$PYTHONPATH:$OONI_REPO
+    fi
+}
 
-# Hack to set the proper sys.path. Overcomes the export PYTHONPATH pain.
-sys.path[:] = map(os.path.abspath, sys.path)
-sys.path.insert(0, os.path.abspath(os.getcwd()))
+function add_exec_dir_to_stack() {
+    cwd_ending=$(echo $(pwd) | awk -F/ '{print $NF}')
+    if [[ "x$cwd_ending" == "xooni" ]]; then
+        pushd $(pwd) 2&>/dev/null       ## $(dirs -l -p -1)    
+    else
+        pushd $OONI_DIR 2&>/dev/null
+    fi
+    export OONI_RUN_PATH="$(popd)/$OONI_EXEC"
+}
 
-# This is a hack to overcome a bug in python
-from ooni.utils.hacks import patched_reduce_ex
-copy_reg._reduce_ex = patched_reduce_ex
+function run_ooni_in_background() {
+    ## :param $1: 
+    ##     The full path to the script to run, i.e. $OONI_RUN_PATH.   
+    coproc $1
+}
 
-from ooni.oonicli import run
-run()
+if [[ "x$#" == "x0" ]]; then
+    usage
+else 
+    check_pythonpath_for_ooni
+    add_ooni_to_pythonpath
+    add_exec_dir_to_stack
+    OONI_START_CMD="python "$OONI_DIR"/"$OONI_EXEC" $@"
+    #run_ooni_in_background $OONI_START_CMD
+    $($OONI_START_CMD)
+fi
diff --git a/ooni/ooniprobe.py b/ooni/ooniprobe.py
old mode 100644
new mode 100755
index 2e23409..c19be5f
--- a/ooni/ooniprobe.py
+++ b/ooni/ooniprobe.py
@@ -12,8 +12,9 @@
 #    The goal of ooni-probe is to collect data about censorship around
 #    the world.
 #
-#    :copyright: (c) 2012 by Arturo Filastò
+#    :copyright: (c) 2012 by Arturo Filastò, Isis Lovecruft
 #    :license: see LICENSE for more details.
+#    :version: 0.0.1-pre-alpha
 #
 
 import sys
@@ -80,17 +81,17 @@ def runTest(test, options, global_options, reactor=reactor):
     log.start(log_to_stdout,
               global_options['log'],
               global_options['verbosity'])
+
     resume = 0
     if not options:
         options = {}
-
     if 'resume' in options:
         resume = options['resume']
 
     test = test_class(options, global_options, report, reactor=reactor)
-
     if test.tool:
         test.runTool()
+        return True
 
     if test.ended:
         print "Ending test"
diff --git a/ooni/runner.py b/ooni/runner.py
index e4f31ba..ea8726f 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -161,7 +161,6 @@ def processTest(obj, config):
 
         options = Options()
         options.parseOptions(config['subArgs'])
-
         obj.localOptions = options
 
         if inputFile:





More information about the tor-commits mailing list