Browse Source

Give a better warning when chutney can't find a binary

teor 5 years ago
parent
commit
8500a1761f
1 changed files with 18 additions and 9 deletions
  1. 18 9
      lib/chutney/TorNet.py

+ 18 - 9
lib/chutney/TorNet.py

@@ -261,6 +261,19 @@ class LocalNodeBuilder(NodeBuilder):
         NodeBuilder.__init__(self, env)
         NodeBuilder.__init__(self, env)
         self._env = 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):
     def _createTorrcFile(self, checkOnly=False):
         """Write the torrc file for this node, disabling any options
         """Write the torrc file for this node, disabling any options
            that are not supported by env's tor binary using comments.
            that are not supported by env's tor binary using comments.
@@ -290,9 +303,7 @@ class LocalNodeBuilder(NodeBuilder):
             except OSError as e:
             except OSError as e:
                 # only catch file not found error
                 # only catch file not found error
                 if e.errno == errno.ENOENT:
                 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)
                     sys.exit(0)
                 else:
                 else:
                     raise
                     raise
@@ -418,9 +429,9 @@ class LocalNodeBuilder(NodeBuilder):
         except OSError as e:
         except OSError as e:
             # only catch file not found error
             # only catch file not found error
             if e.errno == errno.ENOENT:
             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)
                 sys.exit(0)
             else:
             else:
                 raise
                 raise
@@ -448,9 +459,7 @@ class LocalNodeBuilder(NodeBuilder):
         except OSError as e:
         except OSError as e:
             # only catch file not found error
             # only catch file not found error
             if e.errno == errno.ENOENT:
             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)
                 sys.exit(0)
             else:
             else:
                 raise
                 raise