[tor-commits] [ooni-probe/master] Remove now unused stuff from oonicli

isis at torproject.org isis at torproject.org
Thu Oct 4 14:41:15 UTC 2012


commit b7c5c1fec12da443a30f0cbda1ebb44a8ba7612e
Author: Arturo Filastò <arturo at filasto.net>
Date:   Thu Sep 20 19:34:48 2012 +0000

    Remove now unused stuff from oonicli
---
 ooni/oonicli.py |  204 +------------------------------------------------------
 1 files changed, 3 insertions(+), 201 deletions(-)

diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index f0287b4..1e7613b 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -34,68 +34,6 @@ from twisted.python.compat import set
 from twisted.trial import itrial
 from twisted.trial import runner as irunner
 
-
-def _parseLocalVariables(line):
-    """
-    Accepts a single line in Emacs local variable declaration format and
-    returns a dict of all the variables {name: value}.
-    Raises ValueError if 'line' is in the wrong format.
-
-    See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html
-    """
-    paren = '-*-'
-    start = line.find(paren) + len(paren)
-    end = line.rfind(paren)
-    if start == -1 or end == -1:
-        raise ValueError("%r not a valid local variable declaration" % (line,))
-    items = line[start:end].split(';')
-    localVars = {}
-    for item in items:
-        if len(item.strip()) == 0:
-            continue
-        split = item.split(':')
-        if len(split) != 2:
-            raise ValueError("%r contains invalid declaration %r"
-                             % (line, item))
-        localVars[split[0].strip()] = split[1].strip()
-    return localVars
-
-
-def loadLocalVariables(filename):
-    """
-    Accepts a filename and attempts to load the Emacs variable declarations
-    from that file, simulating what Emacs does.
-
-    See http://www.gnu.org/software/emacs/manual/html_node/File-Variables.html
-    """
-    f = file(filename, "r")
-    lines = [f.readline(), f.readline()]
-    f.close()
-    for line in lines:
-        try:
-            return _parseLocalVariables(line)
-        except ValueError:
-            pass
-    return {}
-
-
-def getTestModules(filename):
-    testCaseVar = loadLocalVariables(filename).get('test-case-name', None)
-    if testCaseVar is None:
-        return []
-    return testCaseVar.split(',')
-
-
-def isTestFile(filename):
-    """
-    Returns true if 'filename' looks like a file containing unit tests.
-    False otherwise.  Doesn't care whether filename exists.
-    """
-    basename = os.path.basename(filename)
-    return (basename.startswith('test_')
-            and os.path.splitext(basename)[1] == ('.py'))
-
-
 class Options(usage.Options, app.ReactorSelectionMixin):
     synopsis = """%s [options] [[file|package|module|TestCase|testmethod]...]
     """ % (os.path.basename(sys.argv[0]),)
@@ -104,37 +42,16 @@ class Options(usage.Options, app.ReactorSelectionMixin):
                 "network tests. These are loaded from modules, packages and"
                 "files listed on the command line")
 
-    optFlags = [["help", "h"],
-                ["rterrors", "e", "realtime errors, print out tracebacks as "
-                 "soon as they occur"],
-                ["debug", "b", "Run tests in the Python debugger. Will load "
-                 "'.pdbrc' from current directory if it exists."],
-                ["debug-stacktraces", "B", "Report Deferred creation and "
-                 "callback stack traces"],
-                ["nopm", None, "don't automatically jump into debugger for "
-                 "postmorteming of exceptions"],
-                ["force-gc", None, "Have OONI run gc.collect() before and "
-                 "after each test case."],
-                ["unclean-warnings", None,
-                 "Turn dirty reactor errors into warnings"],
-                ["no-recurse", "N", "Don't recurse into packages"],
-                ['help-reporters', None,
-                 "Help on available output plugins (reporters)"]
-                ]
+    optFlags = [["help", "h"]]
 
     optParameters = [
         ["reportfile", "o", "report.yaml", "report file name"],
         ["logfile", "l", "test.log", "log file name"],
         ['temp-directory', None, '_ooni_temp',
-         'Path to use as working directory for tests.'],
-        ['reporter', None, 'default',
-         'The reporter to use for this test run.  See --help-reporters for '
-         'more info.']]
+         'Path to use as working directory for tests.']
+        ]
 
     compData = usage.Completions(
-        optActions={"tbformat": usage.CompleteList(["plain", "emacs", "cgitb"]),
-                    "logfile": usage.CompleteFiles(descr="log file name"),
-                    },
         extraActions=[usage.CompleteFiles(
                 "*.py", descr="file | module | package | TestCase | testMethod",
                 repeat=True)],
@@ -146,55 +63,6 @@ class Options(usage.Options, app.ReactorSelectionMixin):
         self['test'] = None
         usage.Options.__init__(self)
 
-
-    def coverdir(self):
-        """
-        Return a L{FilePath} representing the directory into which coverage
-        results should be written.
-        """
-        coverdir = 'coverage'
-        result = FilePath(self['temp-directory']).child(coverdir)
-        print "Setting coverage directory to %s." % (result.path,)
-        return result
-
-
-    def opt_coverage(self):
-        """
-        Generate coverage information in the I{coverage} file in the
-        directory specified by the I{trial-temp} option.
-        """
-        import trace
-        self.tracer = trace.Trace(count=1, trace=0)
-        sys.settrace(self.tracer.globaltrace)
-
-
-    def opt_testmodule(self, filename):
-        """
-        Filename to grep for test cases (-*- test-case-name)
-        """
-        # If the filename passed to this parameter looks like a test module
-        # we just add that to the test suite.
-        #
-        # If not, we inspect it for an Emacs buffer local variable called
-        # 'test-case-name'.  If that variable is declared, we try to add its
-        # value to the test suite as a module.
-        #
-        # This parameter allows automated processes (like Buildbot) to pass
-        # a list of files to OONI with the general expectation of "these files,
-        # whatever they are, will get tested"
-        if not os.path.isfile(filename):
-            sys.stderr.write("File %r doesn't exist\n" % (filename,))
-            return
-
-        filename = os.path.abspath(filename)
-        self['test'] = filename
-
-        if isTestFile(filename):
-            self['tests'].add(filename)
-        else:
-            self['tests'].update(getTestModules(filename))
-
-
     def opt_spew(self):
         """
         Print an insanely verbose log of everything that happens.  Useful
@@ -202,61 +70,6 @@ class Options(usage.Options, app.ReactorSelectionMixin):
         """
         sys.settrace(spewer)
 
-
-    def opt_help_reporters(self):
-        synopsis = ("OONI's output can be customized using plugins called "
-                    "Reporters. You can\nselect any of the following "
-                    "reporters using --reporter=<foo>\n")
-        print synopsis
-        for p in plugin.getPlugins(itrial.IReporter):
-            print '   ', p.longOpt, '\t', p.description
-        print
-        sys.exit(0)
-
-
-    def opt_disablegc(self):
-        """
-        Disable the garbage collector
-        """
-        gc.disable()
-
-
-    def opt_tbformat(self, opt):
-        """
-        Specify the format to display tracebacks with. Valid formats are
-        'plain', 'emacs', and 'cgitb' which uses the nicely verbose stdlib
-        cgitb.text function
-        """
-        try:
-            self['tbformat'] = TBFORMAT_MAP[opt]
-        except KeyError:
-            raise usage.UsageError(
-                "tbformat must be 'plain', 'emacs', or 'cgitb'.")
-
-
-    def opt_recursionlimit(self, arg):
-        """
-        see sys.setrecursionlimit()
-        """
-        try:
-            sys.setrecursionlimit(int(arg))
-        except (TypeError, ValueError):
-            raise usage.UsageError(
-                "argument to recursionlimit must be an integer")
-
-
-    def opt_without_module(self, option):
-        """
-        Fake the lack of the specified modules, separated with commas.
-        """
-        for module in option.split(","):
-            if module in sys.modules:
-                warnings.warn("Module '%s' already imported, "
-                              "disabling anyway." % (module,),
-                              category=RuntimeWarning)
-            sys.modules[module] = None
-
-
     def parseArgs(self, *args):
         try:
             self['test'] = args[0]
@@ -265,18 +78,8 @@ class Options(usage.Options, app.ReactorSelectionMixin):
 
 
     def postOptions(self):
-        # Only load reporters now, as opposed to any earlier, to avoid letting
-        # application-defined plugins muck up reactor selecting by importing
-        # t.i.reactor and causing the default to be installed.
         self['reporter'] = reporter.OONIReporter
 
-        if 'tbformat' not in self:
-            self['tbformat'] = 'default'
-        if self['nopm']:
-            if not self['debug']:
-                raise usage.UsageError("you must specify --debug when using "
-                                       "--nopm ")
-            failure.DO_POST_MORTEM = False
 
 def run():
     if len(sys.argv) == 1:
@@ -287,7 +90,6 @@ def run():
     except usage.error, ue:
         raise SystemExit, "%s: %s" % (sys.argv[0], ue)
 
-    file_name = os.path.abspath('nettests/simpletest.py')
     classes = runner.findTestClassesFromFile(config['test'])
     casesList, options = runner.loadTestsAndOptions(classes)
     for idx, cases in enumerate(casesList):





More information about the tor-commits mailing list