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

Print count of object when displaying it

parent cca4ba4e
No related branches found
No related tags found
No related merge requests found
...@@ -197,6 +197,15 @@ class RemoteCommand(OptionCommand): ...@@ -197,6 +197,15 @@ class RemoteCommand(OptionCommand):
def __init__(self, cli, argv0): def __init__(self, cli, argv0):
OptionCommand.__init__(self, cli, argv0) OptionCommand.__init__(self, cli, argv0)
# ignore tag option
self.add_option("-I", "--ignore-tag", action="append", dest="ignore", default=[],
help="Don't display a tag in objects")
# no print count at end option
self.add_option("--no-count", action="store_true", dest="nocount",
help="Don't print count at end of objects")
# index printing
self.add_option("-i", "--index", action="store_true", dest="index",
help="Print object lines indexed")
self.rpc = cli.rpc self.rpc = cli.rpc
def remote_functions(self): def remote_functions(self):
...@@ -209,10 +218,12 @@ class RemoteCommand(OptionCommand): ...@@ -209,10 +218,12 @@ class RemoteCommand(OptionCommand):
return return
# get default index from local options # get default index from local options
_order = objectlist.get("order", None) _order = objectlist.get("order", None)
for (i,o) in enumerate(objectlist["objects"]): for (i, o) in enumerate(objectlist["objects"]):
if self.options.index: if self.options.index:
self.printer.out("[%s] "%i, nl="") self.printer.out("[%s] "%i, nl="")
self.print_tags(o, order=_order) self.print_tags(o, order=_order)
if not self.options.nocount:
self.printer.out("Objects count: %s" % len(objectlist["objects"]))
def print_tags(self, taglist, order=None): def print_tags(self, taglist, order=None):
'''Display a tag with tagdisplay settings''' '''Display a tag with tagdisplay settings'''
...@@ -252,14 +263,9 @@ class TqlCommand(RemoteCommand): ...@@ -252,14 +263,9 @@ class TqlCommand(RemoteCommand):
# set tql status stuff # set tql status stuff
self.add_option("-q", "--quiet", action="store_false", dest="status", self.add_option("-q", "--quiet", action="store_false", dest="status",
help="Dont status of call request") 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 # tql printer option
self.add_option("--print-tql", action="store_true", dest="tql_print", self.add_option("--print-tql", action="store_true", dest="tql_print",
help="Print TQL before sending to server") help="Print TQL before sending to server")
self.add_option("-I", "--ignore-tag", action="append", dest="ignore", default=[],
help="Don't display a tag")
# set tagdisplay stuff # set tagdisplay stuff
self.tdr = self.cli.tagdisplay.resolve self.tdr = self.cli.tagdisplay.resolve
self.tdc = self.cli.tagdisplay.color self.tdc = self.cli.tagdisplay.color
...@@ -372,7 +378,6 @@ class TqlCommand(RemoteCommand): ...@@ -372,7 +378,6 @@ class TqlCommand(RemoteCommand):
raise cmdError("No selected object by TQL.") raise cmdError("No selected object by TQL.")
self.printer.out("Objects:") self.printer.out("Objects:")
self.print_objects(objs) self.print_objects(objs)
self.printer.out("Objects count: %s"%len(objs["objects"]))
# be sure boby want do that # be sure boby want do that
if self.printer.ask("%sProceed?%s (yes): "%(color["lred"], color["reset"])) != "yes": if self.printer.ask("%sProceed?%s (yes): "%(color["lred"], color["reset"])) != "yes":
raise cmdWarning("User aborted") raise cmdWarning("User aborted")
......
...@@ -113,6 +113,9 @@ class Command_list(TqlCommand): ...@@ -113,6 +113,9 @@ class Command_list(TqlCommand):
tmp_pos += 1 tmp_pos += 1
new_line = not found_pos and not first_line new_line = not found_pos and not first_line
self.printer.out("%s%s"%(line, color["reset"])) self.printer.out("%s%s"%(line, color["reset"]))
if not self.options.nocount:
self.printer.out("Objects count: %s" % len(objs["objects"]))
def list_table(self, objs): def list_table(self, objs):
'''Listing table style''' '''Listing table style'''
...@@ -175,6 +178,8 @@ class Command_list(TqlCommand): ...@@ -175,6 +178,8 @@ class Command_list(TqlCommand):
self.printer.out(buf, nl="") self.printer.out(buf, nl="")
self.printer.out(color["reset"]) self.printer.out(color["reset"])
order = order[tag_index:] order = order[tag_index:]
if not self.options.nocount:
self.printer.out("Objects count: %s" % len(objs["objects"]))
def list_vertical(self, objs): def list_vertical(self, objs):
'''Vertical display''' '''Vertical display'''
...@@ -217,6 +222,8 @@ class Command_list(TqlCommand): ...@@ -217,6 +222,8 @@ class Command_list(TqlCommand):
else: else:
line += (buf[:-(margin + 1)] + os.linesep) line += (buf[:-(margin + 1)] + os.linesep)
self.printer.out("%s%s"%(line[:-1], color["reset"])) self.printer.out("%s%s"%(line[:-1], color["reset"]))
if not self.options.nocount:
self.printer.out("Objects count: %s" % len(objs["objects"]))
def list_mikrotik(self, objs): def list_mikrotik(self, objs):
'''Mikrotik style display''' '''Mikrotik style display'''
...@@ -281,6 +288,8 @@ class Command_list(TqlCommand): ...@@ -281,6 +288,8 @@ class Command_list(TqlCommand):
buf, line_pos = self._format_indent_text(self.tdr(tag, o.get(tag)) + " ", line_pos, margin, term_width) buf, line_pos = self._format_indent_text(self.tdr(tag, o.get(tag)) + " ", line_pos, margin, term_width)
line += self.tdc(tag) + buf line += self.tdc(tag) + buf
self.printer.out("%s%s%s"%(line, color["reset"], os.linesep)) self.printer.out("%s%s%s"%(line, color["reset"], os.linesep))
if not self.options.nocount:
self.printer.out("Objects count: %s" % len(objs["objects"]))
def _format_indent_text(self, text, current_pos, min_pos, max_pos): def _format_indent_text(self, text, current_pos, min_pos, max_pos):
'''Reformat text to start in current_pos and fit in column between min_pos and max_pos '''Reformat text to start in current_pos and fit in column between min_pos and max_pos
......
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