From 495db46328b56f703e3fb2a924c70ddf94113eb9 Mon Sep 17 00:00:00 2001 From: Christopher Amin Date: Mon, 7 Mar 2016 21:05:49 +0100 Subject: [PATCH] Only raise the 'No such command' exception if it's the actual command module that isn't found --- scripts/ripe-atlas | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/ripe-atlas b/scripts/ripe-atlas index 84e9a30..85bbebe 100644 --- a/scripts/ripe-atlas +++ b/scripts/ripe-atlas @@ -44,13 +44,23 @@ class RipeAtlas(object): self._setup_command() - try: - module = importlib.import_module( - "ripe.atlas.tools.commands.{}".format(self.command)) - - except ImportError: - raise RipeAtlasToolsException("No such command.") + module_name = "ripe.atlas.tools.commands.{}".format(self.command) + try: + module = importlib.import_module(module_name) + + except ImportError as exc: + if hasattr(exc, "name"): + # Python 3.3+, exc.name will be the full module path + is_command_module = exc.name == module_name + else: + # Python 2.7, message will contain the final part of the path + is_command_module = exc.args[0].rsplit( + " ", 1)[-1] == self.command + if is_command_module: + raise RipeAtlasToolsException("No such command.") + else: + raise # We're missing a dependency # # If the imported module contains a `Factory` class, execute that # to get the `cmd` we're going to use. Otherwise, we expect there