Exemple #1
0
    def getNewCommand(self, cmd, *args, **kwargs):
        """Overloaded from the super so we can ensure that our TableQueryCmd
        objects are properly initialized."""

        cmdkwargs = kwargs.copy()
        if cmd == "fields":
            cmdkwargs['tables'] = self.database.Tables

        try:
            return super(DBCmdLineTool,
                         self).getNewCommand(cmd, *args, **cmdkwargs)
        except CmdLineTool.UnknownCommand:
            # check for a default list to sortby
            sortby = self.sortByCmd.get(cmd)

            kwargs = kwargs.copy()
            kwargs['defaultSort'] = sortby

            try:
                tableobj = self.tableByCmd[cmd]
            except KeyError:
                raise CmdLineTool.UnknownCommand(cmd)

            # assume we need to make a TableQueryCmd object
            cmdobj = self.tableQueryCmd(self.database, tableobj,
                                        self.formatterClass, *args, **kwargs)

            if not cmdobj.usage:
                cmdobj.usage = cmd

            return cmdobj
Exemple #2
0
    def getNewCommand(self, cmd, *args, **kwds):
        """Get a L{CmdLineTool} instance that should be used for the
        provided command.

        @param cmd: name of the command being referenced.
        @type cmd: string

        @return: L{CmdLineTool} that will be used
        @rtype: L{CmdLineTool} instance
        """
        kwds["raiseArgErrors"] = True
        try:
            return self.commands[cmd](*args, **kwds)
        except KeyError:
            raise CmdLineTool.UnknownCommand(cmd)