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

Introduce new object and tags API with server

parent c5bbddf1
No related branches found
No related tags found
No related merge requests found
......@@ -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"]))
......@@ -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'''
......
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