Loading cccli/command.py +28 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ import sys import re import pprint import ConfigParser from optparse import OptionParser import cccli from cccli.exception import * from cccli.printer import color Loading Loading @@ -170,14 +172,33 @@ class Command(object): def cmd_list(self, argv): '''List objects''' if len(argv) == 1: argv.append("a") try: objs = self.cli.rpc.list(str.join("", argv[1:])) oparser = OptionParser(prog="list") oparser.add_option("-t", action="store_true", dest="table") (options, args) = oparser.parse_args(argv[1:]) except SystemExit: return if len(args) == 0: args.append("a") try: objs = self.cli.rpc.list(str.join("", args)) except RpcError as e: raise cmdError("RPCError: %s"%str(e)) if len(objs) == 0: return if options.table: self._list_table(objs) else: self._list(objs) cmd_list.usage = "list [tql]" def _list(self, objs): for o in objs: id = o.pop("id") tags = " ".join([ "%s%s:%s%s"%(color["green"], t, color["reset"], v) for (t,v) in o.items() ]) self.printer.out("%sid:%s%s %s"%(color["green"], color["yellow"], id, tags)) def _list_table(self, objs): # get all tag list tags = dict() for o in objs: Loading @@ -186,17 +207,18 @@ class Command(object): # extract id info idsize = tags.pop("id") # print titles self.printer.out("%s%s%s"%(color["yellow"], "id".ljust(idsize+1), color["reset"]), nl=" ") self.printer.out(color["green"], nl="") self.printer.out("id".ljust(idsize+1), nl=" ") for t,v in tags.items(): self.printer.out(t.ljust(v), nl=" ") self.printer.out() self.printer.out(color["reset"]) # print obj for obj in objs: self.printer.out("%s%s%s"%(color["yellow"], obj.pop("id").ljust(idsize+1), color["reset"]) ,nl=" ") for (t, v) in tags.items(): self.printer.out(str(obj.get(t, "")).ljust(v) ,nl=" ") self.printer.out() cmd_list.usage = "list [tql]" def _startstopsdestroypauseresume(self, argv): # arg stuff Loading Loading
cccli/command.py +28 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ import sys import re import pprint import ConfigParser from optparse import OptionParser import cccli from cccli.exception import * from cccli.printer import color Loading Loading @@ -170,14 +172,33 @@ class Command(object): def cmd_list(self, argv): '''List objects''' if len(argv) == 1: argv.append("a") try: objs = self.cli.rpc.list(str.join("", argv[1:])) oparser = OptionParser(prog="list") oparser.add_option("-t", action="store_true", dest="table") (options, args) = oparser.parse_args(argv[1:]) except SystemExit: return if len(args) == 0: args.append("a") try: objs = self.cli.rpc.list(str.join("", args)) except RpcError as e: raise cmdError("RPCError: %s"%str(e)) if len(objs) == 0: return if options.table: self._list_table(objs) else: self._list(objs) cmd_list.usage = "list [tql]" def _list(self, objs): for o in objs: id = o.pop("id") tags = " ".join([ "%s%s:%s%s"%(color["green"], t, color["reset"], v) for (t,v) in o.items() ]) self.printer.out("%sid:%s%s %s"%(color["green"], color["yellow"], id, tags)) def _list_table(self, objs): # get all tag list tags = dict() for o in objs: Loading @@ -186,17 +207,18 @@ class Command(object): # extract id info idsize = tags.pop("id") # print titles self.printer.out("%s%s%s"%(color["yellow"], "id".ljust(idsize+1), color["reset"]), nl=" ") self.printer.out(color["green"], nl="") self.printer.out("id".ljust(idsize+1), nl=" ") for t,v in tags.items(): self.printer.out(t.ljust(v), nl=" ") self.printer.out() self.printer.out(color["reset"]) # print obj for obj in objs: self.printer.out("%s%s%s"%(color["yellow"], obj.pop("id").ljust(idsize+1), color["reset"]) ,nl=" ") for (t, v) in tags.items(): self.printer.out(str(obj.get(t, "")).ljust(v) ,nl=" ") self.printer.out() cmd_list.usage = "list [tql]" def _startstopsdestroypauseresume(self, argv): # arg stuff Loading