Skip to content
Snippets Groups Projects
Commit bcdb297d authored by Seblu's avatar Seblu
Browse files

list -l and list -t use new objects convention

parent de4072b0
No related branches found
No related tags found
No related merge requests found
...@@ -41,37 +41,40 @@ class Command_list(TqlCommand): ...@@ -41,37 +41,40 @@ class Command_list(TqlCommand):
'''Listing line aligned''' '''Listing line aligned'''
# get max size by tag # get max size by tag
tags = dict() tags = dict()
for o in objs: for o in objs["objects"]:
for (t, v) in o: for (t,v) in o.items():
tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t))) 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 # dislay each object by line
for o in objs: for o in objs["objects"]:
# show others tags line = ""
line = str() for t in order:
for (tagname,tagvalue) in o: line += "%s%s:%s%s "%(self.tdtc(t),
line += "%s%s:%s%s"%(self.tdtc(tagname), t,
tagname, self.tdc(t),
self.tdc(tagname), self.tdr(t, o.get(t, "")).ljust(tags[t]))
self.tdr(tagname, tagvalue).ljust(tags[tagname] + 1))
self.printer.out("%s%s"%(line, color["reset"])) self.printer.out("%s%s"%(line, color["reset"]))
def list_table(self, objs): def list_table(self, objs):
'''Listing table style''' '''Listing table style'''
# get max size by tag # get max size by tag
tags = dict() tags = dict()
for o in objs: for o in objs["objects"]:
for (t,v) in o: for (t,v) in o.items():
tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t))) tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t)))
# print title # build initial print order
for t,v in tags.items(): 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(self.tdtc(t), nl="")
self.printer.out(t.ljust(v), nl=" ") self.printer.out(t.ljust(tags[t]), nl=" ")
self.printer.out(color["reset"]) self.printer.out(color["reset"])
# print obj # print tags in order
for obj in objs: for o in objs["objects"]:
obj = dict(obj) for t in order:
# print others tags
for (t, v) in tags.items():
self.printer.out(self.tdc(t), nl="") 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"]) self.printer.out(color["reset"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment