[tor-commits] [stem/master] Argument to specify tor's path for tor-prompt

atagar at torproject.org atagar at torproject.org
Sat Oct 3 18:51:15 UTC 2015


commit 1c5384ee75be853e57bd620ad833ceb71de2c456
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Oct 3 10:06:47 2015 -0700

    Argument to specify tor's path for tor-prompt
    
    Adding a '--tor' argument to tor-prompt so users can specify tor's path when
    starting an instance. This should especially help when using this for testing
    tor changes.
---
 docs/change_log.rst           |    4 ++++
 stem/interpreter/__init__.py  |   27 ++++++++++++++++-----------
 stem/interpreter/arguments.py |    5 ++++-
 stem/interpreter/settings.cfg |    2 ++
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index b36e143..2933345 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -60,6 +60,10 @@ The following are only available within Stem's `git repository
   * Unable to read descriptors from data directories on Windows due to their CRLF newlines (:trac:`17051`)
   * TypeError under python3 when using 'use_mirrors = True' (:trac:`17083`)
 
+ * **Interpreter**
+
+  * Added a '--tor [path]' argument to specify the tor binary to run.
+
  * **Website**
 
   * Example for `custom path selection for circuits <tutorials/to_russia_with_love.html#custom-path-selection>`_ (:trac:`8728`)
diff --git a/stem/interpreter/__init__.py b/stem/interpreter/__init__.py
index 980e3ba..f8dce7e 100644
--- a/stem/interpreter/__init__.py
+++ b/stem/interpreter/__init__.py
@@ -72,7 +72,7 @@ def main():
     is_tor_running = stem.util.system.is_running('tor') or stem.util.system.is_running('tor.real')
 
     if not is_tor_running:
-      if not stem.util.system.is_available('tor'):
+      if args.tor_path == 'tor' and not stem.util.system.is_available('tor'):
         print(format(msg('msg.tor_unavailable'), *ERROR_OUTPUT))
         sys.exit(1)
       else:
@@ -80,16 +80,21 @@ def main():
 
         control_port = '9051' if args.control_port == 'default' else str(args.control_port)
 
-        stem.process.launch_tor_with_config(
-          config = {
-            'SocksPort': '0',
-            'ControlPort': control_port,
-            'CookieAuthentication': '1',
-            'ExitPolicy': 'reject *:*',
-          },
-          completion_percent = 5,
-          take_ownership = True,
-        )
+        try:
+          stem.process.launch_tor_with_config(
+            config = {
+              'SocksPort': '0',
+              'ControlPort': control_port,
+              'CookieAuthentication': '1',
+              'ExitPolicy': 'reject *:*',
+            },
+            tor_cmd = args.tor_path,
+            completion_percent = 5,
+            take_ownership = True,
+          )
+        except OSError as exc:
+          print(format(msg('msg.unable_to_start_tor', error = exc), *ERROR_OUTPUT))
+          sys.exit(1)
 
   control_port = (args.control_address, args.control_port)
   control_socket = args.control_socket
diff --git a/stem/interpreter/arguments.py b/stem/interpreter/arguments.py
index 2da6410..01920a2 100644
--- a/stem/interpreter/arguments.py
+++ b/stem/interpreter/arguments.py
@@ -17,12 +17,13 @@ DEFAULT_ARGS = {
   'user_provided_port': False,
   'control_socket': '/var/run/tor/control',
   'user_provided_socket': False,
+  'tor_path': 'tor',
   'disable_color': False,
   'print_help': False,
 }
 
 OPT = 'i:s:h'
-OPT_EXPANDED = ['interface=', 'socket=', 'no-color', 'help']
+OPT_EXPANDED = ['interface=', 'socket=', 'tor=', 'no-color', 'help']
 
 
 def parse(argv):
@@ -68,6 +69,8 @@ def parse(argv):
     elif opt in ('-s', '--socket'):
       args['control_socket'] = arg
       args['user_provided_socket'] = True
+    elif opt in ('--tor'):
+      args['tor_path'] = arg
     elif opt == '--no-color':
       args['disable_color'] = True
     elif opt in ('-h', '--help'):
diff --git a/stem/interpreter/settings.cfg b/stem/interpreter/settings.cfg
index 1bacf1c..2739eec 100644
--- a/stem/interpreter/settings.cfg
+++ b/stem/interpreter/settings.cfg
@@ -17,6 +17,7 @@ msg.help
 |  -i, --interface [ADDRESS:]PORT  change control interface from {address}:{port}
 |  -s, --socket SOCKET_PATH        attach using unix domain socket if present,
 |                                    SOCKET_PATH defaults to: {socket}
+|      --tor PATH                  tor binary if tor isn't already running
 |  --no-color                      disables colorized output
 |  -h, --help                      presents this help
 |
@@ -41,6 +42,7 @@ msg.startup_banner
 |
 
 msg.tor_unavailable Tor isn't running and the command currently isn't in your PATH.
+msg.unable_to_start_tor Unable to start tor: {error}
 
 msg.starting_tor
 |Tor isn't running. Starting a temporary Tor instance for our interpreter to





More information about the tor-commits mailing list