From b6566d1646fca3eea5c1e4f7063049db8a25b79f Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 13 2019 15:01:49 +0000 Subject: [PATCH 1/3] add --show-channels listing to list-hosts Fixes: https://pagure.io/koji/issue/1424 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c263a75..c89e1d0 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2771,6 +2771,7 @@ def anon_handle_list_hosts(goptions, session, args): parser.add_option("--not-enabled", action="store_false", dest="enabled", help=_("Limit to not enabled hosts")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) + parser.add_option("--show-channels", action="store_true", help=_("Show host's channels")) (options, args) = parser.parse_args(args) opts = {} activate_session(session, goptions) @@ -2809,10 +2810,25 @@ def anon_handle_list_hosts(goptions, session, args): host['ready'] = yesno(host['ready']) host['arches'] = ','.join(host['arches'].split()) + # pull hosts' channels + if options.show_channels: + session.multicall = True + for host in hosts: + session.listChannels(host['id']) + for host, [channels] in zip(hosts, session.multiCall()): + host['channels'] = ', '.join(sorted([c['name'] for c in channels])) + + longest_host = max([len(h['name']) for h in hosts]) if not options.quiet: - print("Hostname Enb Rdy Load/Cap Arches Last Update") + hdr = "{hostname:<{longest_host}} Enb Rdy Load/Cap Arches Last Update".format(longest_host=longest_host, hostname='Hostname') + if options.show_channels: + hdr += " Channels" + print(hdr) + mask = "%%(name)-%ss %%(enabled)-3s %%(ready)-3s %%(task_load)4.1f/%%(capacity)-4.1f %%(arches)-16s %%(update)s" % longest_host + if options.show_channels: + mask += " %(channels)s" for host in hosts: - print("%(name)-28s %(enabled)-3s %(ready)-3s %(task_load)4.1f/%(capacity)-4.1f %(arches)-16s %(update)s" % host) + print(mask % host) def anon_handle_list_pkgs(goptions, session, args): From 354e3edd3466c87a0e9915c3e260242515e9658e Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 21 2019 13:55:56 +0000 Subject: [PATCH 2/3] fix alignment --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c89e1d0..6faa10a 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2824,7 +2824,7 @@ def anon_handle_list_hosts(goptions, session, args): if options.show_channels: hdr += " Channels" print(hdr) - mask = "%%(name)-%ss %%(enabled)-3s %%(ready)-3s %%(task_load)4.1f/%%(capacity)-4.1f %%(arches)-16s %%(update)s" % longest_host + mask = "%%(name)-%ss %%(enabled)-3s %%(ready)-3s %%(task_load)4.1f/%%(capacity)-4.1f %%(arches)-16s %%(update)-19s" % longest_host if options.show_channels: mask += " %(channels)s" for host in hosts: From fa3363b8419c1c39603df9fe338012e2924a3873 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 21 2019 13:57:20 +0000 Subject: [PATCH 3/3] fix channel separator --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 6faa10a..02c3f6b 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2816,7 +2816,7 @@ def anon_handle_list_hosts(goptions, session, args): for host in hosts: session.listChannels(host['id']) for host, [channels] in zip(hosts, session.multiCall()): - host['channels'] = ', '.join(sorted([c['name'] for c in channels])) + host['channels'] = ','.join(sorted([c['name'] for c in channels])) longest_host = max([len(h['name']) for h in hosts]) if not options.quiet: