commit 8500a1761f70b6969baa3236ce23c6cdb8c1a504 Author: teor teor2345@gmail.com Date: Fri Jul 6 13:52:15 2018 +1000
Give a better warning when chutney can't find a binary --- lib/chutney/TorNet.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py index 3e6da22..ceed4ee 100644 --- a/lib/chutney/TorNet.py +++ b/lib/chutney/TorNet.py @@ -261,6 +261,19 @@ class LocalNodeBuilder(NodeBuilder): NodeBuilder.__init__(self, env) self._env = env
+ def _warnMissingTor(self, tor, cmdline, + tor_name="tor", tor_env="CHUTNEY_TOR"): + """Log a warning that the binary tor can't be found while running + cmdline. Advise the user to put the path to tor_name in the tor_env + environmental variable. + """ + print(("Cannot find the {} binary {} for the command line '{}'. " + + "Use the {} environment variable to set the path, " + + "or put the binary into $PATH: '{}'. " + + "If your $PATH contains ~, use $HOME instead.") + .format(tor_name, tor, " ".join(cmdline), + tor_env, os.getenv("PATH"))) + def _createTorrcFile(self, checkOnly=False): """Write the torrc file for this node, disabling any options that are not supported by env's tor binary using comments. @@ -290,9 +303,7 @@ class LocalNodeBuilder(NodeBuilder): except OSError as e: # only catch file not found error if e.errno == errno.ENOENT: - print("Cannot find tor binary %r. Use " - "CHUTNEY_TOR environment variable to set the " - "path, or put the binary into $PATH." % tor) + self._warnMissingTor(tor, cmdline) sys.exit(0) else: raise @@ -418,9 +429,9 @@ class LocalNodeBuilder(NodeBuilder): except OSError as e: # only catch file not found error if e.errno == errno.ENOENT: - print("Cannot find tor-gencert binary %r. Use " - "CHUTNEY_TOR_GENCERT environment variable to set the " - "path, or put the binary into $PATH." % tor_gencert) + self._warnMissingTor(tor_gencert, cmdline, + tor_name="tor-gencert", + tor_env="CHUTNEY_TOR_GENCERT") sys.exit(0) else: raise @@ -448,9 +459,7 @@ class LocalNodeBuilder(NodeBuilder): except OSError as e: # only catch file not found error if e.errno == errno.ENOENT: - print("Cannot find tor binary %r. Use " - "CHUTNEY_TOR environment variable to set the " - "path, or put the binary into $PATH." % tor) + self._warnMissingTor(tor, cmdline) sys.exit(0) else: raise
tor-commits@lists.torproject.org