[tor-commits] [ooni-probe/master] Updating the ooni/lib structure and git submodules for imports, and I'm trying

isis at torproject.org isis at torproject.org
Thu Sep 13 13:04:15 UTC 2012


commit 174cef2f7f9bfb395fe4753280a881ca5950b504
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue Aug 28 12:02:44 2012 +0000

    Updating the ooni/lib structure and git submodules for imports, and I'm trying
    to keep the syntax the same. Updated the README with info on dev interaction
    with and user cloning of submodules.
---
 README.md            |   22 ++++++++++++++--------
 ooni/lib/__init__.py |   41 ++++++++++++++++++++++++++++++++++++-----
 ooni/lib/txtorcon    |    2 +-
 3 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md
index b39cb2b..7d6e37a 100644
--- a/README.md
+++ b/README.md
@@ -6,27 +6,33 @@
 OONI, the Open Observatory of Network Interference, is a global observation
 network which aims is to collect high quality data using open methodologies,
 using Free and Open Source Software (FL/OSS) to share observations and data
-about the various types, methods, and amounts of network tampering in the world.
+about the various types, methods, and amounts of network tampering in the
+world.
 
 # Let's get started with this already!
 
-To run OONI-probe without having to install it you must tell python that it can
-import modules from the root of ooni-probe.
+To run OONI-probe without having to install it you must tell python that it
+can import modules from the root of ooni-probe, as well as initialize the
+included submodules.
 
-You must therefore run from the root of the repo:
+From the root directory of the repo (.../ooni-probe/), initialize the submodules by doing:
 
-    export PYTHONPATH=$PYTHONPATH:`pwd`
+    $ git submodule init && git submodule update
+
+Next, you will need to tell Python that OONI is part of its path:
+
+    $ export PYTHONPATH=$PYTHONPATH:`pwd`
 
 Then to see what tests are available:
 
-    cd ooni
-    python ooniprobe.py
+    $ cd ooni
+    $ python ooniprobe.py
 
 If you see some errors see INSTALL to install the missing dependencies.
 
 To list the help for a specific test:
 
-    python ooniprobe.py httpt --help
+    $ python ooniprobe.py httpt --help
 
 
 # More details
diff --git a/ooni/lib/__init__.py b/ooni/lib/__init__.py
index fac7035..0fd36c5 100644
--- a/ooni/lib/__init__.py
+++ b/ooni/lib/__init__.py
@@ -1,9 +1,40 @@
+import pkgutil
 import sys
-import os
+from os import listdir, path
 
-pwd = os.path.dirname(__file__)
-#child_path = os.path.normpath(os.path.join(pwd, '..'))
-#sys.path.append(child_path)
-sys.path.append(pwd)
+__all__ = ['txtorcon', 'txscapy', 'txtraceroute']
 
+__sub_modules__ = [ ]
 
+def callback(arg, directory, files):
+    for file in listdir(directory):
+        fullpath = path.abspath(file)
+        if path.isdir(fullpath) and not path.islink(fullpath):
+            __sub_modules__.append(fullpath)
+            sys.path.append(fullpath)
+
+path.walk(".", callback, None)
+
+def load_submodules(init, list):
+    for subdir in list:
+        contents=[x for x in pkgutil.iter_modules(path=subdir, 
+                                                  prefix='ooni.lib.')]
+        for loader, module_name, ispkg in contents:
+            init_dot_module = init + "." + module_name
+            if init_dot_module in sys.modules:
+                module = sys.modules[module_name]
+            else:
+                if module_name in __all__:
+                    grep = loader.find_module(module_name)
+                    module = grep.load_module(module_name)
+                else:
+                    module = None
+
+            if module is not None:
+                globals()[module_name] = module
+
+load_submodules(__name__, __sub_modules__)
+
+print "system paths are: %s" % sys.path
+print "globals are: %s" % globals()
+print "system modules are: %s" % sys.modules
diff --git a/ooni/lib/txtorcon b/ooni/lib/txtorcon
index ac791b4..def1551 160000
--- a/ooni/lib/txtorcon
+++ b/ooni/lib/txtorcon
@@ -1 +1 @@
-Subproject commit ac791b4ddfc29a2dd29a7044f34c3394df38653d
+Subproject commit def155177f4ba6fd0728922e5b6f3c0066006a94





More information about the tor-commits mailing list