Ejemplo n.º 1
0
    def do_addalias(self,*arg):
        """
        Create a command shortcut for a function.

        The alias is just a way of making shortcuts for repetitive taks
          >>alias myalias, 'myfun(args)'
        results in
          >>myalias
        being repackaged to
          >>myfun(args)
        which is then sent to the interpretor

        Note alias's are added to the command list
        (see 'show' and 'help addcmd')

        Example:
        --------
        pds>alias "code", "cd('~/code')"
        pds>code
        pds>pwd
        /home/bob/code
        """
        if len(arg) == 1:
            arg = arg[0]
            words = arg.split(',')
            if len(words) != 2:
                print "Error parsing cmd/func names"
            cmd_name  = words[0].strip()
            func_name = words[1].strip()
        elif len(arg) == 2:
            cmd_name  = arg[0].strip()
            func_name = arg[1].strip()
        else:
            print "Wrong number of arguments"
            return SUCCESS
        cmd_name  = trimstring(cmd_name)
        func_name = trimstring(func_name)

        if len(cmd_name) == 0 or len(func_name) == 0:
            print "Error parsing cmd/func names"
            return SUCCESS

        # do a check
        if cmd_name in PYTHON_KEY_WORDS:
            print "Error: command '%s' is a python keyword" % cmd_name
            return SUCCESS

        s = "__%s__ = lambda : %s" % (cmd_name,func_name)
        ret = self.exec_line(s)
        s = "addcmd '%s', '__%s__'" % (cmd_name,cmd_name)
        ret = self.exec_line(s)
Ejemplo n.º 2
0
    def do_addalias(self, *arg):
        """
        Create a command shortcut for a function.

        The alias is just a way of making shortcuts for repetitive taks
          >>alias myalias, 'myfun(args)'
        results in
          >>myalias
        being repackaged to
          >>myfun(args)
        which is then sent to the interpretor

        Note alias's are added to the command list
        (see 'show' and 'help addcmd')

        Example:
        --------
        pds>alias "code", "cd('~/code')"
        pds>code
        pds>pwd
        /home/bob/code
        """
        if len(arg) == 1:
            arg = arg[0]
            words = arg.split(',')
            if len(words) != 2:
                print "Error parsing cmd/func names"
            cmd_name = words[0].strip()
            func_name = words[1].strip()
        elif len(arg) == 2:
            cmd_name = arg[0].strip()
            func_name = arg[1].strip()
        else:
            print "Wrong number of arguments"
            return SUCCESS
        cmd_name = trimstring(cmd_name)
        func_name = trimstring(func_name)

        if len(cmd_name) == 0 or len(func_name) == 0:
            print "Error parsing cmd/func names"
            return SUCCESS

        # do a check
        if cmd_name in PYTHON_KEY_WORDS:
            print "Error: command '%s' is a python keyword" % cmd_name
            return SUCCESS

        s = "__%s__ = lambda : %s" % (cmd_name, func_name)
        ret = self.exec_line(s)
        s = "addcmd '%s', '__%s__'" % (cmd_name, cmd_name)
        ret = self.exec_line(s)
Ejemplo n.º 3
0
    def do_addcmd(self,*arg):
        """
        Add a command interface to a function
        
        Allows a function to be called with command syntax.
          >>addcmd mycmd, myfun
        results in
          >>mycmd arg1, arg2, key=xx
        being repackaged to
          >>myfun(arg1,arg2,key=xx)
        which is then sent to the interpretor
        """
        if len(arg) == 1:
            arg = arg[0]
            words = arg.split(',')
            if len(words) != 2:
                print "Error parsing cmd/func names"
            cmd_name = words[0].strip()
            func_name = words[1].strip()
        elif len(arg) == 2:
            cmd_name  = arg[0].strip()
            func_name = arg[1].strip()
        else:
            print "Wrong number of arguments"
            return SUCCESS
        cmd_name  = trimstring(cmd_name)
        func_name = trimstring(func_name)

        if len(cmd_name) == 0 or len(func_name) == 0:
            print "Error parsing cmd/func names"
            return SUCCESS
        
        # do a check
        if cmd_name in PYTHON_KEY_WORDS:
            print "Error: command '%s' is a python keyword" % cmd_name
            return SUCCESS
        
        if cmd_name in self.pds_commands.keys():
            print "Error: command '%s' is a builtin keyword" % cmd_name
            return SUCCESS

        if cmd_name in self.commands.keys():
            print "Warning: overwriting command '%s' " % cmd_name
            self.commands[cmd_name] = func_name
        else:
            self.commands.update({cmd_name:func_name})
        return SUCCESS
Ejemplo n.º 4
0
    def do_addcmd(self, *arg):
        """
        Add a command interface to a function
        
        Allows a function to be called with command syntax.
          >>addcmd mycmd, myfun
        results in
          >>mycmd arg1, arg2, key=xx
        being repackaged to
          >>myfun(arg1,arg2,key=xx)
        which is then sent to the interpretor
        """
        if len(arg) == 1:
            arg = arg[0]
            words = arg.split(',')
            if len(words) != 2:
                print "Error parsing cmd/func names"
            cmd_name = words[0].strip()
            func_name = words[1].strip()
        elif len(arg) == 2:
            cmd_name = arg[0].strip()
            func_name = arg[1].strip()
        else:
            print "Wrong number of arguments"
            return SUCCESS
        cmd_name = trimstring(cmd_name)
        func_name = trimstring(func_name)

        if len(cmd_name) == 0 or len(func_name) == 0:
            print "Error parsing cmd/func names"
            return SUCCESS

        # do a check
        if cmd_name in PYTHON_KEY_WORDS:
            print "Error: command '%s' is a python keyword" % cmd_name
            return SUCCESS

        if cmd_name in self.pds_commands.keys():
            print "Error: command '%s' is a builtin keyword" % cmd_name
            return SUCCESS

        if cmd_name in self.commands.keys():
            print "Warning: overwriting command '%s' " % cmd_name
            self.commands[cmd_name] = func_name
        else:
            self.commands.update({cmd_name: func_name})
        return SUCCESS