[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Add RUN_IN_DIR as a commandline option and cleanup the option explanations.
commit 50316521c08e216a760ba8bd89334f50b15e61e7
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Sat Oct 26 08:39:44 2013 +0000
Add RUN_IN_DIR as a commandline option and cleanup the option explanations.
---
lib/bridgedb/Main.py | 18 +++++++++---------
lib/bridgedb/opt.py | 38 ++++++++++++++++++++++++++------------
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index 76f0832..e12c268 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -459,6 +459,7 @@ def startup(cfg, options):
db.close()
if cfg.PIDFILE:
os.unlink(cfg.PIDFILE)
+ sys.exit()
def run(options):
"""This is the main entry point into BridgeDB.
@@ -476,17 +477,16 @@ def run(options):
options.getUsage()
sys.exit(1)
- configFile = options['config']
- execfile(configFile, configuration)
- C = Conf(**configuration)
- configuration = C
-
# Change to the directory where we're supposed to run.
- if configuration.RUN_IN_DIR:
- os.chdir(os.path.expanduser(configuration.RUN_IN_DIR))
+ if options['rundir']:
+ os.chdir(options['rundir'])
+
+ execfile(options['config'], configuration)
+ config = Conf(**configuration)
+
if options['dump-bridges']:
- bucketManager = Bucket.BucketManager(configuration)
+ bucketManager = Bucket.BucketManager(config)
bucketManager.assignBridgesToBuckets()
bucketManager.dumpBridges()
else:
- startup(configuration, options)
+ startup(config, options)
diff --git a/lib/bridgedb/opt.py b/lib/bridgedb/opt.py
index 8018544..bedfaec 100644
--- a/lib/bridgedb/opt.py
+++ b/lib/bridgedb/opt.py
@@ -15,15 +15,14 @@
"""
from __future__ import print_function
+from __future__ import unicode_literals
import sys
import textwrap
+import os
from twisted.python import usage
-# from ._version import get_versions
-# __version__ = get_versions()['version']
-# del get_versions
from bridgedb import __version__
@@ -51,19 +50,34 @@ class BaseOptions(usage.Options):
"""Base options included in all main and sub options menus."""
longdesc = textwrap.dedent("""BridgeDB is a proxy distribution system for
- private relays acting as bridges into the Tor network.""")
+ 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:
+ rundir = os.path.join(os.getcwdu(), 'run')
+ else:
+ try:
+ rundir = os.path.abspath(os.path.expanduser(rundir))
+ except Exception as error:
+ raise usage.UsageError(error.message)
+ if rundir and os.path.isdir(rundir):
+ self['rundir'] = rundir
+ opt_r = opt_rundir
+
def __init__(self):
"""Create an options parser. All flags, parameters, and attributes of
this base options parser are inherited by all child classes.
"""
usage.Options.__init__(self)
+ self['rundir'] = os.path.join(os.getcwdu(), 'run')
self['version'] = self.opt_version
def opt_version(self):
- """Display BridgeDB version and exit."""
+ """Display BridgeDB's version and exit."""
print("%s-%s" % (__package__, __version__))
sys.exit()
@@ -71,6 +85,9 @@ class BaseOptions(usage.Options):
class TestOptions(BaseOptions):
"""Suboptions for running twisted.trial and unittest based tests."""
+ longdesc = textwrap.dedent("""BridgeDB testing commands.
+ See the `bridgedb mock` command for generating testing environments.""")
+
optFlags = [['coverage', 'c', 'Generate coverage statistics']]
optParameters = [
['descriptors', 'n', 1000, 'Generate <N> fake bridge descriptors'],
@@ -96,12 +113,9 @@ class MainOptions(BaseOptions):
"""Main commandline options parser for BridgeDB."""
optFlags = [
- ['reload', 'r',
- 'Reload bridge descriptors by sending a SIGHUP to BridgeDB'],
- ['dump-bridges', 'd', 'Dump bridges by hashring assignment into files']]
+ ['dump-bridges', 'd', 'Dump bridges by hashring assignment into files'],
+ ['reload', 'R', 'Reload bridge descriptors into running servers']]
optParameters = [
- ['config', 'c', './bridgedb.conf', 'Configuration file']]
-
+ ['config', 'c', 'bridgedb.conf', 'Configuration file']]
subCommands = [
- ['test', None, TestOptions,
- "Run twisted.trial tests or unittests (see `bridgedb test --help`)"]]
+ ['test', None, TestOptions, "Run twisted.trial tests or unittests"]]
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits