def _execute(self, cmdName): try: if cmdName in self.authRequired and self._isLoggedIn(self.commandInstance.user): self._executeCommand(cmdName) elif cmdName not in self.authRequired: self._executeCommand(cmdName) else: self.reply("The command 'user.%s' requires that you are authenticated. Use the user.identify command to log in to the system, and try again." % cmdName) except Exception as e: util.writeException(sys.exc_info())
def help(self, command): """ Look up the docstring for a given module or method from a module. """ command = command[5:] cmdClass, cmdMethod, cmdArgs = self._splitCommand(command) util.write("Finding docstring for %s.%s" % (cmdClass, cmdMethod)) try: # If there is only a module (ie $test) if cmdClass is None or cmdClass == '': self.replyWithMessage( "Usage: help module.command to get information on a specific command, or help module to just get info on the module." ) elif cmdMethod is None: docString = util.getDocstring( self.grabClass(cmdClass) ) self.replyWithMessage( "%s: %s" % (command.title(), docString) ) # If there is also a method on the module, and it isn't a private # method (ie $test.testing) elif not cmdMethod.startswith('_'): docString = util.getDocstring( cmdMethod, targetClass=self.grabClass(cmdClass) ) self.replyWithMessage( "%s.%s: %s" % (cmdClass.title(), cmdMethod, docString) ) else: self.replyWithMessage( "Docstring: Methods starting with _ are private methods!" ) except (AttributeError, KeyError): if cmdMethod is not None: self.replyWithMessage( "Docstring: Command %s.%s was not found" % (cmdClass, cmdMethod) ) else: self.replyWithMessage( "Docstring: Module '%s' was not found" % cmdClass ) except Exception as e: self.replyWithMessage("Docstring: Exception occured: %s " % e) util.writeException(sys.exc_info())
def execute(self, command): """ Execute the command by seperating it on '.' and then taking the first index, (e.g. test.testing) and use the module 'src.modules.test.test' and the class Test, then pass the second index 'testing' as an arg to the __init__ of the class, which then executes the method. """ cmdClass, cmdMethod, cmdArgs = self._splitCommand(command) util.write("Executing %s.%s with args: %s" % ( cmdClass, cmdMethod, cmdArgs )) try: # If there is only a module (ie $test) if cmdMethod is None: publicMethods = util.publicMethods( self.grabClass(cmdClass) ) self.replyWithMessage( "%s: %s" % (command.title(), publicMethods) ) # If there is also a method on the module, and it isn't a private # method (ie $test.testing) elif not cmdMethod.startswith('_'): self.grabClass(cmdClass)(self, cmdName=cmdMethod, cmdArgs=cmdArgs) else: self.replyWithMessage( "Methods starting with _ are private methods!" ) except (AttributeError, KeyError): if cmdMethod is not None: self.replyWithMessage( "Command %s.%s was not found" % (cmdClass, cmdMethod) ) else: self.replyWithMessage( "Module '%s' was not found" % cmdClass ) except Exception as e: self.replyWithMessage("Exception occured during command execution: %s " % e) util.writeException(sys.exc_info())