def _load_cmd(self, cmd_name, cmd_ref): """Because some cmds are stored in the cache as either a class or as a path to the .py file, this method is needed to disambiguate. Given the following arguments: cmd_name: The name of the cmd. cmd_ref: Either the OttoCmd object or the path to it's file. This method will always return the corresponding OttoCmd class.""" # Base cmds are already loaded if isOttoCmd(cmd_ref): return cmd_ref # Otherwise, import and return OttoCmd subclass try: cmd_module = imp.load_source( cmd_name, cmd_ref ) cmd_class = getattr(cmd_module, cmd_name.capitalize(), None) if not isOttoCmd(cmd_class): msg = "'%s' could not be loaded from %s" % (cmd_name, cmd_ref) bail(msg) else: return cmd_class except SyntaxError as e: errmsg = "Syntax error found:\nFile:%s (%s, %s)" % e.args[1][:3] bail(errmsg) except Exception as e: raise e
def lookup(self, name): """Given a name, determine the best possible pack and cmd.""" pack, cmd = cmd_split(name) if pack is None: pack = self.find_pack(cmd) if self.is_used(pack, cmd): return pack, cmd else: bail("Couldn't lookup %s, are you sure it's installed?" % name)