def addCommand(self, name, func, arguments=None, argoptions=None, helptext=""): """ Registers a command. @param name: the name of the command to add @type name: string @param func: the function that handles the command @type func: function @param arguments: the argument spec to create the argparser @type arguments: string @param argoptions: options for how the argument spec should be parsed @type argoptions: string @param helptext: the help text for this command for the user @type helptext: string @raise ValueError: if the function is uncallable @raise Exception: if the argument spec for the command is unparseable """ if not callable(func): raise ValueError, "%s is uncallable." % name cd = _CommandData() syntaxline = "" # try to figure out the arguments and syntax line stuff if arguments != None: try: cd.setName(name) cd.setArgParser(argparser.ArgumentParser( arguments, argoptions)) syntaxline = utils.wrap_text(cd.getArgParser().syntaxline, 60, 6) except Exception, e: raise Exception, "Error with arguments for command %s, (%s)" % ( name, e)
def addCommand(self, name, func, arguments=None, argoptions=None, helptext=""): """ Registers a command. @param name: the name of the command to add @type name: string @param func: the function that handles the command @type func: function @param arguments: the argument spec to create the argparser @type arguments: string @param argoptions: options for how the argument spec should be parsed @type argoptions: string @param helptext: the help text for this command for the user @type helptext: string @raise ValueError: if the function is uncallable @raise Exception: if the argument spec for the command is unparseable """ if not callable(func): raise ValueError, "%s is uncallable." % name cd = _CommandData() syntaxline = "" # try to figure out the arguments and syntax line stuff if arguments != None: try: cd.setName(name) cd.setArgParser(argparser.ArgumentParser(arguments, argoptions)) syntaxline = utils.wrap_text(cd.getArgParser().syntaxline, 60, 6) except Exception, e: raise Exception, "Error with arguments for command %s, (%s)" % (name,e)
def config_cmd(ses, args, input): """ Allows you to view and change configuration options that affect how Lyntin functions. Configuration options can be session oriented or global to all of Lyntin. examples: #config displays global configuration and session configuration for the current session #a #config displays global configuration and session configuration for the session named 'a' #config ansicolor displays information about the mudecho configuration option #config ansicolor on sets the ansicolor configuration option to on category: commands """ name = args["name"] value = args["value"] quiet = args["quiet"] c = exported.myengine.getConfigManager() # if they didn't specify a name, then we print out all the # configuration stuff for general and this session if not name: general = c.getConfigItems(None) globmap = {} for mem in general: globmap[mem._name] = mem.toString() seslisting = c.getConfigItems(ses) sesmap = {} for mem in seslisting: sesmap[mem._name] = mem.toString() output = "Commandline:\n" output += _fixmap(16, config.options) + "\n" output += "Global:\n" output += _fixmap(16, globmap) + "\n" output += "Session:\n" output += _fixmap(16, sesmap) + "\n" exported.write_message(output, ses) return # try to find a session item first ci = c.getConfigItem(name, ses) if not ci: ci = c.getConfigItem(name) if not ci: exported.write_error("config: config manager does not recognize %s as a config item." % name) return if not value: # we print out everything we know about this config item. output = "config: %s\n\ncurrent value: %s\n\n%s\n" % \ (name, ci.toString(), utils.wrap_text(ci._description, wraplength=60)) exported.write_message(output) return try: try: c.change(name, value, ses) except: c.change(name, value) if not quiet: exported.write_message("config: %s set to %s." % (name, value), ses) except Exception, e: exported.write_error(str(e))
def config_cmd(ses, args, input): """ Allows you to view and change configuration options that affect how Lyntin functions. Configuration options can be session oriented or global to all of Lyntin. examples: #config displays global configuration and session configuration for the current session #a #config displays global configuration and session configuration for the session named 'a' #config ansicolor displays information about the mudecho configuration option #config ansicolor on sets the ansicolor configuration option to on category: commands """ name = args["name"] value = args["value"] quiet = args["quiet"] c = exported.myengine.getConfigManager() # if they didn't specify a name, then we print out all the # configuration stuff for general and this session if not name: general = c.getConfigItems(None) globmap = {} for mem in general: globmap[mem._name] = mem.toString() seslisting = c.getConfigItems(ses) sesmap = {} for mem in seslisting: sesmap[mem._name] = mem.toString() output = "Commandline:\n" output += _fixmap(16, config.options) + "\n" output += "Global:\n" output += _fixmap(16, globmap) + "\n" output += "Session:\n" output += _fixmap(16, sesmap) + "\n" exported.write_message(output, ses) return # try to find a session item first ci = c.getConfigItem(name, ses) if not ci: ci = c.getConfigItem(name) if not ci: exported.write_error( "config: config manager does not recognize %s as a config item." % name) return if not value: # we print out everything we know about this config item. output = "config: %s\n\ncurrent value: %s\n\n%s\n" % \ (name, ci.toString(), utils.wrap_text(ci._description, wraplength=60)) exported.write_message(output) return try: try: c.change(name, value, ses) except: c.change(name, value) exported.write_message("config: %s set to %s." % (name, value), ses) except Exception, e: exported.write_error(e)
def addCommand(self, name, func, arguments=None, argoptions=None, helptext=""): """ Registers a command. @param name: the name of the command to add @type name: string @param func: the function that handles the command @type func: function @param arguments: the argument spec to create the argparser @type arguments: string @param argoptions: options for how the argument spec should be parsed @type argoptions: string @param helptext: the help text for this command for the user @type helptext: string @raise ValueError: if the function is uncallable @raise Exception: if the argument spec for the command is unparseable """ if not callable(func): raise ValueError("%s is uncallable." % name) cd = _CommandData() syntaxline = "" # try to figure out the arguments and syntax line stuff if arguments != None: try: cd.setName(name) cd.setArgParser(argparser.ArgumentParser(arguments, argoptions)) syntaxline = utils.wrap_text(cd.getArgParser().syntaxline, 60, 6) except Exception as e: raise Exception("Error with arguments for command %s, (%s)" % (name,e)) cd.setFunc(func) # removeCommand tests to see if the command exists already and will # remove it if it does. self.removeCommand(name) # toss the command thing in the dict self._commands[name] = cd # deal with the help text if not helptext: if func.__doc__: helptext = inspect.getdoc(func) else: helptext = "\nThis command has no help." if name.startswith("^"): cd.setNameAdjusted(name[1:]) else: cd.setNameAdjusted(name) if syntaxline: commandchar = self._engine.getConfigManager().get("commandchar") helptext = ("syntax: %s%s %s\n" % (commandchar, cd.getNameAdjusted(), syntaxline) + helptext) fqn = exported.add_help(cd.getNameAdjusted(), helptext) cd.setFQN(fqn)