[tor-commits] [bridgedb/master] Fix the interface between bridgedb and the descriptor generator.

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:30 UTC 2014


commit fd4d3007997b2d827fc95b30edbcde93e331f3e0
Author: Isis Lovecruft <isis at torproject.org>
Date:   Sat Oct 26 08:49:18 2013 +0000

    Fix the interface between bridgedb and the descriptor generator.
---
 lib/bridgedb/opt.py    |   27 +++++++++++++++++++++++----
 lib/bridgedb/runner.py |   26 ++++++++++++--------------
 setup.py               |    9 +++++----
 3 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/lib/bridgedb/opt.py b/lib/bridgedb/opt.py
index bedfaec..d3532b6 100644
--- a/lib/bridgedb/opt.py
+++ b/lib/bridgedb/opt.py
@@ -53,8 +53,6 @@ class BaseOptions(usage.Options):
     private relays acting as bridges into the Tor network. See `bridgedb
     <command> --help` for addition help.""")
 
-    optFlags = [['verbose', 'v', 'Log to stdout']]
-
     def opt_rundir(self, rundir):
         """Change to this directory"""
         if not rundir:
@@ -75,6 +73,19 @@ class BaseOptions(usage.Options):
         usage.Options.__init__(self)
         self['rundir'] = os.path.join(os.getcwdu(), 'run')
         self['version'] = self.opt_version
+        self['verbosity'] = 30
+
+    def opt_quiet(self):
+        """Decrease verbosity"""
+        # We use '10' because then it corresponds to the log levels
+        self['verbosity'] -= 10
+
+    def opt_verbose(self):
+        """Increase verbosity"""
+        self['verbosity'] += 10
+
+    opt_q = opt_quiet
+    opt_v = opt_verbose
 
     def opt_version(self):
         """Display BridgeDB's version and exit."""
@@ -90,7 +101,6 @@ class TestOptions(BaseOptions):
 
     optFlags = [['coverage', 'c', 'Generate coverage statistics']]
     optParameters = [
-        ['descriptors', 'n', 1000, 'Generate <N> fake bridge descriptors'],
         ['file', 'f', None, 'Run tests in specific file(s) (trial only)'],
         ['unittests', 'u', False, 'Run unittests in bridgedb.Tests'],
         ['trial', 't', True, 'Run twisted.trial tests in bridgedb.test']]
@@ -108,6 +118,14 @@ class TestOptions(BaseOptions):
         """Parse any additional arguments after the options and flags."""
         self['test_args'] = args
 
+class MockOptions(BaseOptions):
+    """Suboptions for creating necessary conditions for testing purposes."""
+
+    optParameters = [
+        ['descriptors', 'n', 1000,
+         '''Generate <n> mock bridge descriptor sets
+          (types: netstatus, extrainfo, server)''']]
+
 
 class MainOptions(BaseOptions):
     """Main commandline options parser for BridgeDB."""
@@ -118,4 +136,5 @@ class MainOptions(BaseOptions):
     optParameters = [
         ['config', 'c', 'bridgedb.conf', 'Configuration file']]
     subCommands = [
-        ['test', None, TestOptions, "Run twisted.trial tests or unittests"]]
+        ['test', None, TestOptions, "Run twisted.trial tests or unittests"],
+        ['mock', None, MockOptions, "Generate a testing environment"]]
diff --git a/lib/bridgedb/runner.py b/lib/bridgedb/runner.py
index 7f38e95..3ba61ec 100644
--- a/lib/bridgedb/runner.py
+++ b/lib/bridgedb/runner.py
@@ -32,24 +32,22 @@ def generateDescriptors(options):
     """
     import subprocess
 
+    proc = None
+    rundir = options['rundir']
     script = 'gen_bridge_descriptors'
     count = options.subOptions['descriptors']
     try:
-        print("Generating %s bridge descriptors..." % str(howmany))
-        proc = subprocess.Popen([script, str(count)])
-    except Exception as exc:
-        print(exc)
-        print("There was an error generating bridge descriptors.")
-    else:
-        proc.wait()
-        if proc.returncode:
-            print("There was an error generating bridge descriptors. (%s: %d)"
-                  % ("Returncode", proc.returncode))
-        else:
-            print("Sucessfully bridge generated descriptors.")
+        proc = subprocess.Popen([script, '-n', str(count)],
+                                close_fds=True, cwd=rundir)
     finally:
-        del subprocess
-    return
+        if proc is not None:
+            proc.wait()
+            if proc.returncode:
+                print("There was an error generating bridge descriptors.",
+                      "(Returncode: %d)" % proc.returncode)
+            else:
+                print("Sucessfully bridge generated descriptors.")
+    del subprocess
 
 def runTrial(options):
     """Run Twisted trial based unittests, optionally with coverage.
diff --git a/setup.py b/setup.py
index d01f646..f73347f 100644
--- a/setup.py
+++ b/setup.py
@@ -74,7 +74,6 @@ install_i18n = os.path.join('bridgedb', 'i18n')
 # Directory to install docs, license, and other text resources into:
 install_docs = os.path.join('share', 'doc', 'bridgedb')
 
-
 def get_cmdclass():
     """Get our cmdclass dictionary for use in setuptool.setup().
 
@@ -255,11 +254,13 @@ setuptools.setup(
     url='https://www.torproject.org',
     download_url='https://gitweb.torproject.org/bridgedb.git',
     package_dir={'': 'lib'},
-    packages=['bridgedb'],
+    packages=['bridgedb',
+              'bridgedb.parse',
+              'bridgedb.test'],
     scripts=['scripts/bridgedb',
              'scripts/gen_bridge_descriptors'],
-    extras_require={'test': ["sure>=0.4.5",
-                             "trialcoverage>=0.3.12"]},
+    extras_require={'test': ["sure==0.4.5",
+                             "trialcoverage==0.3.12"]},
     zip_safe=False,
     cmdclass=get_cmdclass(),
     include_package_data=True,





More information about the tor-commits mailing list