[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Refactor scripts/bridgedb to use the new options and runner.



commit 831a778b054cf6425de953bb86eeae3be69ceac1
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Tue Oct 15 14:08:14 2013 +0000

    Refactor scripts/bridgedb to use the new options and runner.
---
 scripts/bridgedb |   54 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 21 deletions(-)

diff --git a/scripts/bridgedb b/scripts/bridgedb
index 8e8800b..0e20cd9 100644
--- a/scripts/bridgedb
+++ b/scripts/bridgedb
@@ -1,31 +1,43 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@xxxxxxxxxxxxxx>
+#           please also see AUTHORS file
+# :copyright: (c) 2007-2013, The Tor Project, Inc.
+#             (c) 2007-2013, all entities within the AUTHORS file
+# :license: 3-clause BSD, see included LICENSE for information
+
+from __future__ import print_function
 
 import bridgedb
+import os
 import sys
 
-if len(sys.argv) == 1:
-    from bridgedb import Main
-    Main.run()
-else:
-    if sys.argv[1] in ('test', 'coverage'):
-        import os
-        from twisted.scripts import trial
+from bridgedb import runner
+from bridgedb import opt
 
-        if sys.argv[1] == 'coverage':
-            run_python_coverage = True
 
-        # Hack to set the PYTHONPATH:
-        sys.path[:] = map(os.path.abspath, sys.path)
-        sys.path.insert(0, os.path.abspath(os.getcwd()))
+options = opt.parseOptions()
 
-        if run_python_coverage:
-            from coverage import coverage
-            cov = coverage()
-            cov.start()
+if options.subCommand is not None:
+    # Hack to set the PYTHONPATH:
+    sys.path[:] = map(os.path.abspath, sys.path)
+    sys.path.insert(0, os.path.abspath(os.getcwd()))
+    sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '../lib')))
 
-        sys.argv = ['trial', 'bridgedb']
-        trial.run()
+    if 'descriptors' in options.subOptions:
+        runner.generateDescriptors(options.subOptions['descriptors'])
 
-        if run_python_coverage:
-            cov.stop()
-            cov.html_report('.coverage-results')
+    if options.subCommand == 'test':
+        if options.subOptions['trial']:
+            runner.runTrial(options.subOptions)
+        if options.subOptions['unittests']:
+            runner.runTests(options.subOptions)
+    sys.exit()
+
+# If no suboption was given, just run bridgedb:
+else:
+    from bridgedb import Main
+    Main.run(options)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits