diff --git a/cccli/command/command.py b/cccli/command/command.py index 79a42ec56f2a1bd59263718716c2a7115ea36d4c..d7120e824b42cf50fcfaf6b4923932b464aa48ab 100644 --- a/cccli/command/command.py +++ b/cccli/command/command.py @@ -158,7 +158,7 @@ class TqlCommand(OptionCommand): if _options["callback"] is not None: _options["callback"](d) if _options["status"]: - self.print_status(d) + self.print_objects(d, ("output")) return d except RpcError as e: if _options["exception"]: @@ -173,48 +173,58 @@ class TqlCommand(OptionCommand): except RpcError as e: raise cmdError("RPCError: %s"%str(e)) # no result, goodbye - if len(objs) == 0: + if len(objs["objects"]) == 0: raise cmdError("No selected object by TQL.") self.printer.out("Objects:") - self.print_taglist(objs) - self.printer.out("Objects count: %s"%len(objs)) + self.print_objects(objs) + 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": raise cmdWarning("User aborted") # bobby doing many things, he needs to be really sure! - if len(objs) > 5: + if len(objs["objects"]) > 5: self.printer.out("%sYou will act on more than 5 objets!%s"%(color["uyellow"], color["reset"])) if self.printer.ask("%sAre you really sure?%s (Yes Mistress): " %(color["lred"], color["reset"])) != "Yes Mistress": raise cmdWarning("User aborted") # per validated id execution (this is a kind of atomic implementation) - for obj in objs: - dobj = dict(obj) + for obj in objs["objects"]: try: l = list(args) - l[_options["tql_index"]] = "id=%s"%dobj["id"] + l[_options["tql_index"]] = "id=%s"%obj["id"] d = self.cli.rpc.call(*tuple(l), **kwargs) if _options["callback"] is not None: - _options["callback"](d) + _options["callback"](obj["output"]) if _options["status"]: - self.print_status(d) + self.print_objects(d, ("output")) except RpcError as e: self.printer.error("RPCError: %s"%str(e)) - def print_taglist(self, objs): - '''Trivial listing of tag''' - for o in objs: - self.print_tags(o) + def print_objects(self, objectlist, ignore=None): + '''Trivial objectlist printing of tag''' + if objectlist is None: + return + _order = objectlist.get("order", None) + for o in objectlist["objects"]: + self.print_tags(o, order=_order, ignore=ignore) - def print_tags(self, taglist): + def print_tags(self, taglist, order=None, ignore=None): '''Display a tag with tagdisplay settings''' - line = list() - for (tn, tv) in taglist: - line.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) - self.printer.out("%s%s"%(" ".join(line), color["reset"])) - - def print_status(self, outputlist): - '''Display status from an object list ''' - if outputlist is not None: - for o in outputlist: - self.print_tags(o[1][1]) + _ignore = () if ignore is None else ignore + _order = () if order is None else order + # copy dict to show + tl = taglist.copy() + # remove ignore tags + for tn in _ignore: + tl.pop(tn, None) + # list to print + pls = [] + # print firstly order tags + for tn in _order: + tv = tl.pop(tn, None) + if tv is not None: + pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) + # print next tags without order + for (tn, tv) in tl.items(): + pls.append("%s%s:%s%s"%(self.tdtc(tn), tn, self.tdc(tn), self.tdr(tn, tv))) + self.printer.out("%s%s"%(" ".join(pls), color["reset"])) diff --git a/cccli/command/list.py b/cccli/command/list.py index e16bfe11000631276da007fbe83a89dcc72e1806..57ef6b0974b518bea3e9a9aeecc08be40dd1a22e 100644 --- a/cccli/command/list.py +++ b/cccli/command/list.py @@ -35,7 +35,7 @@ class Command_list(TqlCommand): elif self.options.table: self.list_table(objs) else: - self.print_taglist(objs) + self.print_objects(objs) def list_align(self, objs): '''Listing line aligned'''