[tor-commits] [ooni-probe/master] Rename oonicli to ooniprobe

art at torproject.org art at torproject.org
Thu May 31 03:01:43 UTC 2012


commit 37d160cd14422b5e21707d97e1fc128fad6a9b5e
Author: Arturo Filastò <hellais at torproject.org>
Date:   Thu May 31 04:51:33 2012 +0200

    Rename oonicli to ooniprobe
---
 ooni/oonicli.py   |  117 -----------------------
 ooni/ooniprobe.py |  272 ++++++++++++++++++++---------------------------------
 2 files changed, 101 insertions(+), 288 deletions(-)

diff --git a/ooni/oonicli.py b/ooni/oonicli.py
deleted file mode 100755
index d612ba7..0000000
--- a/ooni/oonicli.py
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: UTF-8
-#
-#    oonicli
-#    *******
-#
-#    :copyright: (c) 2012 by Arturo Filastò
-#    :license: see LICENSE for more details.
-#
-
-import sys
-
-from twisted.python import usage
-from twisted.plugin import getPlugins
-from twisted.internet import reactor
-
-from zope.interface.exceptions import BrokenImplementation
-from zope.interface.exceptions import BrokenMethodImplementation
-from zope.interface.verify import verifyObject
-from pprint import pprint
-
-from ooni.plugoo import tests, work, assets, reports
-from ooni.logo import getlogo
-from ooni import plugins, log
-
-__version__ = "0.0.1-prealpha"
-
-def retrieve_plugoo():
-    """
-    Get all the plugins that implement the ITest interface and get the data
-    associated to them into a dict.
-    """
-    interface = tests.ITest
-    d = {}
-    error = False
-    for p in getPlugins(interface, plugins):
-        try:
-            verifyObject(interface, p)
-            d[p.shortName] = p
-        except BrokenImplementation, bi:
-            print "Plugin Broken"
-            print bi
-            error = True
-    if error != False:
-        print "Plugin Loaded!"
-    return d
-
-plugoo = retrieve_plugoo()
-
-def runTest(test, options, global_options):
-
-    parallelism = int(global_options['parallelism'])
-    worker = work.Worker(parallelism)
-    test = plugoo[test].__class__
-    report = reports.Report(global_options['output'])
-
-    #if options['asset']:
-    #    print options['asset']
-    #    asset = assets.Asset(options['asset'])
-    #    print asset
-    log.start(global_options['log'], 1)
-
-    wgen = work.WorkGenerator(test(options, global_options, report),
-                              dict(options),
-                              start=options['resume'])
-
-    for x in wgen:
-        worker.push(x)
-
-    reactor.run()
-
-class Options(usage.Options):
-    tests = plugoo.keys()
-    subCommands = []
-    for test in tests:
-        subCommands.append([test, None, plugoo[test].options, "Run the %s test" % test])
-
-    optFlags = [
-        #['remote', 'r', "If the test should be run remotely (not supported)"],
-        #['status', 'x', 'Show current state'],
-        #['restart', 'r', 'Restart OONI']
-    ]
-
-    optParameters = [
-        ['parallelism', 'n', 10, "Specify the number of parallel tests to run"],
-        #['target-node', 't', 'localhost:31415', 'Select target node'],
-        ['output', 'o', 'report.log', "Specify output report file"],
-        ['log', 'l', 'oonicli.log', "Specify output log file"],
-        #['password', 'p', 'opennetwork', "Specify the password for authentication"],
-    ]
-
-    def opt_version(self):
-        """
-        Display OONI version and exit.
-        """
-        print "OONI version:", __version__
-        sys.exit(0)
-
-    def __str__(self):
-        """
-        Hack to get the sweet ascii art into the help output and replace the
-        strings "Commands" with "Tests".
-        """
-        return getlogo() + '\n' + self.getSynopsis() + '\n' + \
-               self.getUsage(width=None).replace("Commands:", "Tests:")
-
-config = Options()
-config.parseOptions()
-
-if not config.subCommand:
-    print "Error! No Test Specified."
-    config.opt_help()
-    sys.exit(1)
-
-runTest(config.subCommand, config.subOptions, config)
-
-
diff --git a/ooni/ooniprobe.py b/ooni/ooniprobe.py
index 3e8fbe7..d75b9b9 100755
--- a/ooni/ooniprobe.py
+++ b/ooni/ooniprobe.py
@@ -1,191 +1,121 @@
 #!/usr/bin/env python
 # -*- coding: UTF-8
-"""
-    ooniprobe
-    **********
+#
+#    ooniprobe
+#    *********
+#
+#    Open Observatory of Network Interference
+#
+#    "The Net interprets censorship as damage and routes around it."
+#                    - John Gilmore; TIME magazine (6 December 1993)
+#
+#    The goal of ooni-probe is to collect data about censorship around
+#    the world.
+#
+#    :copyright: (c) 2012 by Arturo Filastò
+#    :license: see LICENSE for more details.
+#
 
-    Open Observatory of Network Interference
-
-    "The Net interprets censorship as damage and routes around it."
-                    - John Gilmore; TIME magazine (6 December 1993)
-
-    The goal of ooni-probe is to collect data about censorship around
-    the world.
-
-    :copyright: (c) 2012 by Arturo Filastò
-    :license: see LICENSE for more details.
-"""
-
-import imp
-import os
 import sys
-import argparse
 
+from twisted.python import usage
+from twisted.plugin import getPlugins
+from twisted.internet import reactor
+
+from zope.interface.exceptions import BrokenImplementation
+from zope.interface.exceptions import BrokenMethodImplementation
+from zope.interface.verify import verifyObject
 from pprint import pprint
 
-import plugoo
-from utils import Storage, parse_asset, import_test, get_logger
-from config import Config
-from logo import getlogo
+from ooni.plugoo import tests, work, assets, reports
+from ooni.logo import getlogo
+from ooni import plugins, log
+
+__version__ = "0.0.1-prealpha"
 
-class ooni(object):
+def retrieve_plugoo():
     """
-    ooni-probe is a suite designed to run tests on your
-    network to detect censorship.
-    This is the main class that is used to start ooni probe
-    select the assets and run tests.
+    Get all the plugins that implement the ITest interface and get the data
+    associated to them into a dict.
     """
-    def __init__(self):
-        self.config = Storage()
-        self.config.main = Config("main")
-        self.config.tests = Config("tests")
-        self.config.report = Config("report")
-
-        self.logger = get_logger(self.config.main)
-
-        self.logger.info("Started ooni-probe")
-
-        self.assets = []
-        self.get_assets()
-
-        self.tests = Storage()
-        #self.load_tests()
-
-        self.runtests = self.config.tests.run.split(",")
-
-
-    def get_assets(self):
+    interface = tests.ITest
+    d = {}
+    error = False
+    for p in getPlugins(interface, plugins):
+        try:
+            verifyObject(interface, p)
+            d[p.shortName] = p
+        except BrokenImplementation, bi:
+            print "Plugin Broken"
+            print bi
+            error = True
+    if error != False:
+        print "Plugin Loaded!"
+    return d
+
+plugoo = retrieve_plugoo()
+
+def runTest(test, options, global_options):
+
+    parallelism = int(global_options['parallelism'])
+    worker = work.Worker(parallelism)
+    test = plugoo[test].__class__
+    report = reports.Report(global_options['output'])
+
+    log.start(global_options['log'], 1)
+
+    wgen = work.WorkGenerator(test(options, global_options, report),
+                              dict(options),
+                              start=options['resume'])
+
+    for x in wgen:
+        worker.push(x)
+
+    reactor.run()
+
+class Options(usage.Options):
+    tests = plugoo.keys()
+    subCommands = []
+    for test in tests:
+        subCommands.append([test, None, plugoo[test].options, "Run the %s test" % test])
+
+    optFlags = [
+        #['remote', 'r', "If the test should be run remotely (not supported)"],
+        #['status', 'x', 'Show current state'],
+        #['restart', 'r', 'Restart OONI']
+    ]
+
+    optParameters = [
+        ['parallelism', 'n', 10, "Specify the number of parallel tests to run"],
+        #['target-node', 't', 'localhost:31415', 'Select target node'],
+        ['output', 'o', 'report.log', "Specify output report file"],
+        ['log', 'l', 'oonicli.log', "Specify output log file"],
+        #['password', 'p', 'opennetwork', "Specify the password for authentication"],
+    ]
+
+    def opt_version(self):
         """
-        Parse all the assets in the asset directory.
-        Assets can optionaly contain the ooni-probe asset file
-        format: #:<something> <something_else>, that will then
-        be used to render the asset details to the user.
-        It is also possible to have an asset file link to multiple
-        other files.
+        Display OONI version and exit.
         """
-        for root, dir, files in os.walk(self.config.main.assetdir):
-            for name in files:
-                asset = os.path.join(root, name)
-                self.assets.append(parse_asset(asset))
+        print "OONI version:", __version__
+        sys.exit(0)
 
-    def list_assets(self):
-        """
-        Enumerate all the assets in the directory specified
-        in the config file
-        """
-        print "[-] There are a total of %s assets loaded" % len(self.assets)
-        for asset in self.assets:
-            print "    name: %s" % asset.name
-            if asset.desc:
-                print "    description: %s" % asset.desc
-            if asset.files:
-                print "    files: %s" % asset.files
-            if asset.tests:
-                print "    tests: %s" % asset.tests
-            print ""
-
-    def load_tests(self):
+    def __str__(self):
         """
-        Iterate through the plugoos inside the folder specified by the
-        config file and instantiate them.
+        Hack to get the sweet ascii art into the help output and replace the
+        strings "Commands" with "Tests".
         """
-        pluginfiles = [fname[:-3] for fname in os.listdir(self.config.main.testdir)\
-                         if fname.endswith(".py")]
-        for fname in pluginfiles:
-            test = Storage()
-            test_name = fname
-            if not self.config.main.testdir in sys.path:
-                sys.path.insert(0, self.config.main.testdir)
-            #print "Fname: %s\n__import__(%s)" % (fname, fname)
-            #print sys.path
-            module = __import__(fname)
-            try:
-                test.name = module.__plugoo__
-                test.desc = module.__desc__
-                test.module = module
-            except Exception, e:
-                self.logger.warning("Soft fail %s", e)
-                test.name = test_name
-                test.desc = ""
-                test.module = module
-
-            try:
-                self.tests[test_name] = test
-            except Exception, e:
-                print "Failed to load the test %s %s" % (name, e)
-
-    def list_tests(self):
-        """
-        Print the loaded plugoonis to screen
-        """
-        self.load_tests()
-        print "[-] There are a total of %s tests available" % len(self.tests)
-        for name, test in self.tests.items():
-            print "    name: %s" % name
-            if test.name:
-                print "    long name: %s" % test.name
-            if test.desc:
-                print "    description: %s" % test.desc
-            print ""
-
-
-    def run_tests(self):
-        """
-        Run all the tests that have been loaded
-        """
-        self.load_tests()
-        for name in self.runtests:
-            self.logger.info("running %s" % name)
-            try:
-                self.tests[name].module.run(self)
-            except Exception, e:
-                self.logger.error("ERR: %s" % e)
-
-    def run_test(self, test, asset=None):
-        """
-        Run a single test
-        """
-        self.load_tests()
-        if asset:
-            self.tests[test].module.run(self, asset)
-        else:
-            self.tests[test].module.run(self)
-
-if __name__ == "__main__":
-    o = ooni()
-
-    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
-                                     description=getlogo() +
-                                     '\n\n Open Observatory of Network Interference.')
-
-    parser.add_argument('-t', '--list-tests', help='List all the available tests',
-                        action='store_true', dest='list_tests')
-
-    parser.add_argument('-l', '--list-assets', help='List all the assets',
-                        action='store_true', dest='list_assets')
-
-    parser.add_argument('-r', '--run', help='Run a certain test', action='store')
-
-    parser.add_argument('-a', '--asset', help='Use this asset for the test',
-                        action='store')
-
-    parser.add_argument('--runall', help='Run all the tests in the config',
-                        action='store_true')
-
-    args = parser.parse_args()
-
-    if args.list_tests:
-        o.list_tests()
+        return getlogo() + '\n' + self.getSynopsis() + '\n' + \
+               self.getUsage(width=None).replace("Commands:", "Tests:")
 
-    if args.list_assets:
-        o.list_assets()
+config = Options()
+config.parseOptions()
 
-    if args.run:
-        o.run_test(args.run, args.asset)
+if not config.subCommand:
+    print "Error! No Test Specified."
+    config.opt_help()
+    sys.exit(1)
 
-    elif args.runall:
-        o.run_tests()
+runTest(config.subCommand, config.subOptions, config)
 
-    elif len(sys.argv) < 2:
-        parser.print_help()
 





More information about the tor-commits mailing list