Commit 6b4f7c29 authored by Seblu's avatar Seblu
Browse files

TqlCommand now handle index option

parent 8c63a804
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ class TqlCommand(OptionCommand):
        # set tql status stuff
        self.add_option("-q", "--quiet", action="store_false", dest="status",
                        help="Dont status of call request")
        # index printing
        self.add_option("-i", "--index", action="store_true", dest="index",
                        help="Print TQL line index")
        # tql printer option
        self.add_option("--print-tql", action="store_true", dest="tql_print",
                        help="Print TQL before sending to server")
@@ -126,8 +129,9 @@ class TqlCommand(OptionCommand):
        _exception: catch or not RPCError exception
        '''

        # set default option value
        # set rpccall default option value
        _options = { "status": True,
                     "index": False,
                     "direct": False,
                     "exception": False,
                     "tql": "",
@@ -168,7 +172,7 @@ class TqlCommand(OptionCommand):
            if _options["callback"] is not None:
                _options["callback"](d)
            if _options["status"]:
                self.print_objects(d, ["output"])
                self.print_objects(d, ["output"], index=_options["index"])
            return d
        except RpcError as e:
            if _options["exception"]:
@@ -186,7 +190,7 @@ class TqlCommand(OptionCommand):
        if len(objs["objects"]) == 0:
            raise cmdError("No selected object by TQL.")
        self.printer.out("Objects:")
        self.print_objects(objs)
        self.print_objects(objs, index=_options["index"])
        self.printer.out("Objects count: %s"%len(objs["objects"]))
        # be sure boby want do that
        if self.printer.ask("%sProceed?%s (yes): "%(color["lred"], color["reset"])) != "yes":
@@ -206,16 +210,18 @@ class TqlCommand(OptionCommand):
                if _options["callback"] is not None:
                    _options["callback"](obj)
                if _options["status"]:
                    self.print_objects(d, ["output"])
                    self.print_objects(d, ["output"], index=False)
            except RpcError as e:
                self.printer.error("RPCError: %s"%str(e))

    def print_objects(self, objectlist, ignore=None):
    def print_objects(self, objectlist, ignore=None, index=False):
        '''Trivial objectlist printing of tag'''
        if objectlist is None:
            return
        _order = objectlist.get("order", None)
        for o in objectlist["objects"]:
        for (i,o) in enumerate(objectlist["objects"]):
            if index:
                self.printer.out("[%s] "%i, nl="")
            self.print_tags(o, order=_order, ignore=ignore)

    def print_tags(self, taglist, order=None, ignore=None):