Exemplo n.º 1
0
    def complete_current(self):
        out = None

        if self.prev_str == "--modules":
            out = self.complete_modules()
        elif self.prev_str == "--":
            out = self.complete_key()
        elif self.prev_str.startswith("--"):
            if self.prev_arg == None:
                out = ""
            elif self.prev_arg.type != "bool":
                for i in range(len(self.cdl)):
                    arg = "--" + self.cdl[i].name
                    if arg == self.prev_str:
                        out = self.value_completion()
            else:
                out = self.complete_key()
        else:
            arg_with_no_key = utils.get_arg_with_no_key(self.args)
            needs_no_key = utils.needs_no_key(self.cdl)
            if self.args.index(self.cur_str) == arg_with_no_key:
                self.prev_arg = needs_no_key
                out = self.value_completion()
            else:
                out = self.complete_key()

        return out
Exemplo n.º 2
0
    def complete_key(self):
        out = {"type": "key", 
               "required": [],
               "optional": [],
               "length": 1,
               "matched": 0}

        arg_with_no_key = utils.get_arg_with_no_key(self.args)
        needs_no_key = utils.needs_no_key(self.cdl)
        for i in range(len(self.cdl)):
            if (self.cdl[i].type == "path" or self.cdl[i].type == "node") and (arg_with_no_key != -1) and (needs_no_key != None):
                pass
            else:
                arg = "--" + self.cdl[i].name
                if arg not in self.args and arg.startswith(self.cur_str):
                    if len(arg) > out["length"]:
                        out["length"] = len(arg)
                    if self.cdl[i].optional:
                        out["optional"].append(arg)
                    else:
                        out["required"].append(arg)
                    out["matched"] += 1

        if out["matched"] == 0:
            out = ""
            
        elif out["matched"] == 1:
            if len(out["required"]) == 0:
                out = out["optional"][0]
            else:
                out = out["required"][0]

        return out
Exemplo n.º 3
0
    def complete_current(self):
        out = None

        if self.prev_str == "--modules":
            out = self.complete_modules()
        elif self.prev_str == "--":
            out = self.complete_key()
        elif self.prev_str.startswith("--"):
            if self.prev_arg == None:
                out = ""
            elif self.prev_arg.type != "bool":
                for i in range(len(self.cdl)):
                    arg = "--" + self.cdl[i].name
                    if arg == self.prev_str:
                        out = self.value_completion()
            else:
                out = self.complete_key()
        else:
            arg_with_no_key = utils.get_arg_with_no_key(self.args)
            needs_no_key = utils.needs_no_key(self.cdl)
            if self.args.index(self.cur_str) == arg_with_no_key:
                self.prev_arg = needs_no_key
                out = self.value_completion()
            else:
                out = self.complete_key()

        return out
Exemplo n.º 4
0
    def complete_empty(self):
        out = None

        if self.prev_str == "--":
            out = ""

        if self.prev_str == "--modules":
            out = self.complete_modules()

        elif self.prev_str.startswith("--"):
            if self.prev_arg == None:
                out = ""
            elif self.prev_arg.type != "bool":
                out = self.value_completion()
            else:
                arg_with_no_key = utils.get_arg_with_no_key(self.args)
                needs_no_key = utils.needs_no_key(self.cdl)
                if arg_with_no_key == -1 and needs_no_key != None:
                    if (needs_no_key.type in ["path", "node"
                                              ]) or (len(self.cvl) > 0):
                        self.prev_arg = needs_no_key
                        out = self.value_completion()
                    else:
                        out = self.complete_key()
                else:
                    out = self.complete_key()
        else:
            arg_with_no_key = utils.get_arg_with_no_key(self.args)
            needs_no_key = utils.needs_no_key(self.cdl)
            if arg_with_no_key == -1 and needs_no_key != None:
                if (needs_no_key.type in ["path", "node"
                                          ]) or (len(self.cvl) > 0):
                    self.prev_arg = needs_no_key
                    out = self.value_completion()
                else:
                    out = self.complete_key()
            else:
                out = self.complete_key()

        return out
Exemplo n.º 5
0
    def complete_empty(self):
        out = None

        if self.prev_str == "--":
            out = ""

        if self.prev_str == "--modules":
            out = self.complete_modules()

        elif self.prev_str.startswith("--"):
            if self.prev_arg == None:
                out = ""
            elif self.prev_arg.type != "bool":
                out = self.value_completion()
            else:
                arg_with_no_key = utils.get_arg_with_no_key(self.args)
                needs_no_key = utils.needs_no_key(self.cdl)
                if arg_with_no_key == -1 and needs_no_key != None:
                    if (needs_no_key.type in ["path", "node"]) or (len(self.cvl) > 0):
                        self.prev_arg = needs_no_key
                        out = self.value_completion()
                    else:
                        out = self.complete_key()
                else:
                    out = self.complete_key()
        else:
            arg_with_no_key = utils.get_arg_with_no_key(self.args)
            needs_no_key = utils.needs_no_key(self.cdl)
            if arg_with_no_key == -1 and needs_no_key != None:
                if (needs_no_key.type in ["path", "node"]) or (len(self.cvl) > 0):
                    self.prev_arg = needs_no_key
                    out = self.value_completion()
                else:
                    out = self.complete_key()
            else:
                out = self.complete_key()

        return out
Exemplo n.º 6
0
    def several_argument(self, cdl, args, gen_arg):
        res = 0

        i = 0
        needs_no_key = utils.needs_no_key(cdl)
        priority = utils.keyPriority(cdl)
        arg_with_no_key = utils.get_arg_with_no_key(args)
        while i != (len(cdl)) and res == 0:
            func = self.get_func_generator(cdl[i])
            if func != None:
                key = "--" + cdl[i].name
                if key not in args:
                    if cdl[i].optional == False:
                        if needs_no_key != None and arg_with_no_key != -1:
                            value = args[arg_with_no_key]
                            res = func(cdl[i].name, value, gen_arg)
                            arg_with_no_key = -1
                        else:
                            print "Argument error: the argument <", cdl[
                                i].name, "> is required by command: <", args[
                                    0], ">"
                            res = -1
                    else:
                        if arg_with_no_key != -1 and len(
                                priority[0]) == 0 and len(priority[1]) == 1:
                            if cdl[i].name == priority[1][0].name:
                                value = args[arg_with_no_key]
                                res = func(cdl[i].name, value, gen_arg)
                            else:
                                res = func(cdl[i].name, None, gen_arg)
                        else:
                            res = func(cdl[i].name, None, gen_arg)
                else:
                    key_idx = args.index(key)
                    if cdl[i].type == "bool":
                        res = func(cdl[i].name, "", gen_arg)
                    else:
                        if (key_idx) == len(args) - 1:
                            print "Key error: the argument <", key, "> needs a value"
                            res = -1
                        else:
                            value = args[key_idx + 1]
                            res = func(cdl[i].name, value, gen_arg)
            else:
                res = -1

            i += 1

        return res
Exemplo n.º 7
0
    def several_argument(self, cdl, args, gen_arg):
        res = 0

        i = 0
        needs_no_key = utils.needs_no_key(cdl)
        priority = utils.keyPriority(cdl)
        arg_with_no_key = utils.get_arg_with_no_key(args)
        while i != (len(cdl)) and res == 0:
            func = self.get_func_generator(cdl[i])
            if func != None:
                key = "--" + cdl[i].name
                if key not in args:
                    if cdl[i].optional == False:
                        if needs_no_key != None and arg_with_no_key != -1:
                            value = args[arg_with_no_key]
                            res = func(cdl[i].name, value, gen_arg)
                            arg_with_no_key = -1
                        else:
                            print "Argument error: the argument <", cdl[i].name, "> is required by command: <", args[0], ">"
                            res = -1
                    else:
                        if arg_with_no_key != -1 and len(priority[0]) == 0 and len(priority[1]) == 1:
                            if cdl[i].name == priority[1][0].name:
                                value = args[arg_with_no_key]
                                res = func(cdl[i].name, value, gen_arg)
                            else:
                                res = func(cdl[i].name, None, gen_arg)
                        else:
                            res = func(cdl[i].name, None, gen_arg)
                else:
                    key_idx = args.index(key)
                    if cdl[i].type == "bool":
                        res = func(cdl[i].name, "", gen_arg)
                    else:
                        if (key_idx) == len(args) - 1:
                            print "Key error: the argument <", key, "> needs a value"
                            res = -1
                        else:
                            value = args[key_idx + 1]
                            res = func(cdl[i].name, value, gen_arg)
            else:
                res = -1
            
            i += 1

        return res
Exemplo n.º 8
0
    def complete_key(self):
        out = {
            "type": "key",
            "required": [],
            "optional": [],
            "length": 1,
            "matched": 0
        }

        arg_with_no_key = utils.get_arg_with_no_key(self.args)
        needs_no_key = utils.needs_no_key(self.cdl)
        for i in range(len(self.cdl)):
            if (self.cdl[i].type == "path" or self.cdl[i].type == "node") and (
                    arg_with_no_key != -1) and (needs_no_key != None):
                pass
            else:
                arg = "--" + self.cdl[i].name
                if arg not in self.args and arg.startswith(self.cur_str):
                    if len(arg) > out["length"]:
                        out["length"] = len(arg)
                    if self.cdl[i].optional:
                        out["optional"].append(arg)
                    else:
                        out["required"].append(arg)
                    out["matched"] += 1

        if out["matched"] == 0:
            out = ""

        elif out["matched"] == 1:
            if len(out["required"]) == 0:
                out = out["optional"][0]
            else:
                out = out["required"][0]

        return out