diff --git a/cccli/command/list.py b/cccli/command/list.py index 57ef6b0974b518bea3e9a9aeecc08be40dd1a22e..ea5ff37f8fd89c318942f4ad7c5e1fff768d276d 100644 --- a/cccli/command/list.py +++ b/cccli/command/list.py @@ -41,37 +41,40 @@ class Command_list(TqlCommand): '''Listing line aligned''' # get max size by tag tags = dict() - for o in objs: - for (t, v) in o: + for o in objs["objects"]: + for (t,v) in o.items(): tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t))) + # build initial print order + order = [ t for t in objs.get("order", []) if t in tags ] + order.extend(sorted(set(tags.keys()) - set(order))) # dislay each object by line - for o in objs: - # show others tags - line = str() - for (tagname,tagvalue) in o: - line += "%s%s:%s%s"%(self.tdtc(tagname), - tagname, - self.tdc(tagname), - self.tdr(tagname, tagvalue).ljust(tags[tagname] + 1)) + for o in objs["objects"]: + line = "" + for t in order: + line += "%s%s:%s%s "%(self.tdtc(t), + t, + self.tdc(t), + self.tdr(t, o.get(t, "")).ljust(tags[t])) self.printer.out("%s%s"%(line, color["reset"])) def list_table(self, objs): '''Listing table style''' # get max size by tag tags = dict() - for o in objs: - for (t,v) in o: + for o in objs["objects"]: + for (t,v) in o.items(): tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t))) - # print title - for t,v in tags.items(): + # build initial print order + order = [ t for t in objs.get("order", []) if t in tags ] + order.extend(sorted(set(tags.keys()) - set(order))) + # print tag title in order + for t in order: self.printer.out(self.tdtc(t), nl="") - self.printer.out(t.ljust(v), nl=" ") + self.printer.out(t.ljust(tags[t]), nl=" ") self.printer.out(color["reset"]) - # print obj - for obj in objs: - obj = dict(obj) - # print others tags - for (t, v) in tags.items(): + # print tags in order + for o in objs["objects"]: + for t in order: self.printer.out(self.tdc(t), nl="") - self.printer.out(self.tdr(t, obj.get(t, u"")).ljust(v) ,nl=" ") + self.printer.out(self.tdr(t, o.get(t, u"")).ljust(tags[t]) ,nl=" ") self.printer.out(color["reset"])