From 6b4f7c299a5bc473b97bb2cf2e31b81b452d3e58 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Wed, 23 Feb 2011 15:02:16 +0100 Subject: [PATCH] TqlCommand now handle index option --- cccli/command/command.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cccli/command/command.py b/cccli/command/command.py index 2fe2a5e..868581b 100644 --- a/cccli/command/command.py +++ b/cccli/command/command.py @@ -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): -- GitLab