コード例 #1
0
ファイル: __init__.py プロジェクト: makeittotop/py_queue
    def parseArgs(self, *args, **kwargs):
        # before calling the super, we need to check for argument aliases
        newargs = []
        # check for any argument aliases
        uprefs = self.parent.userPrefs
        for arg in kwargs["args"]:
            try:
                alias = uprefs.aliases.args.cmds[self.usage][arg]
            except (AttributeError, KeyError):
                try:
                    alias = uprefs.aliases.args["global"][arg]
                except (AttributeError, KeyError):
                    alias = self.aliases.get(arg)

            if alias:
                # split the string on whitespace, keeping quoted strings together
                addargs = stringutil.quotedSplit(alias, removeQuotes=True)
            else:
                addargs = [arg]

            for arg in addargs:
                # could do additional processing of args here before committing to newargs
                newargs.append(arg)

        # update the kwargs with our new argument list
        kwargs["args"] = newargs
        
        # now call the super
        return super(QueryCmd, self).parseArgs(*args, **kwargs)
コード例 #2
0
    def getCommandToRun(self):
        try:
            return super(TractorCLT, self).getCommandToRun()
        except CmdLineTool.UnknownCommand, err:
            # check for the fields command which we will redirect to the
            # main help command
            if self.args and self.args[0] == "fields":
                command = "help"
                cmdobj = self.getCommand(command)
                args = ["fields"] + self.args[1:]

                return (command, cmdobj, args)

            # check the user prefs for command aliases
            try:
                alias = self.userPrefs.aliases.command[self.args[0]]
            except (AttributeError, KeyError):
                # check the global command alias list
                alias = self.aliases.get(self.args[0])

            if alias:
                # check for additional arguments in the alias
                import rpg.stringutil as stringutil
                aliasArgs = stringutil.quotedSplit(alias, removeQuotes=True)
                command   = aliasArgs[0]
                cmdobj    = self.getCommand(command)
                args      = aliasArgs[1:] + self.args[1:]
                return (command, cmdobj, args)

            raise CmdLineTool.UnknownCommand, err