From 990a78f762d1d86d8af93d143a84bf29fb7b4a97 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 29 2018 13:05:35 +0000 Subject: [PATCH 1/3] Add --enabled --ready filters for list-channels Fixes: https://pagure.io/koji/issue/939 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index a9c14ac..7033e75 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2706,12 +2706,16 @@ def anon_handle_list_channels(goptions, session, args): parser = OptionParser(usage=usage) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) + parser.add_option("--ready", action="store_true", + help=_("List only ready builders")) + parser.add_option("--enabled", action="store_true", + help=_("List only enabled builders")) (options, args) = parser.parse_args(args) activate_session(session, goptions) channels = session.listChannels() session.multicall = True for channel in channels: - session.listHosts(channelID=channel['id']) + session.listHosts(channelID=channel['id'], ready=options.ready, enabled=options.enabled) for channel, hosts in zip(channels, session.multiCall()): channel['hosts'] = len(hosts[0]) if not options.quiet: From 01894353cce4d11df75a363fd616cf93780f7d7b Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 29 2018 13:05:35 +0000 Subject: [PATCH 2/3] display more info --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 7033e75..e8651d0 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2706,22 +2706,20 @@ def anon_handle_list_channels(goptions, session, args): parser = OptionParser(usage=usage) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) - parser.add_option("--ready", action="store_true", - help=_("List only ready builders")) - parser.add_option("--enabled", action="store_true", - help=_("List only enabled builders")) (options, args) = parser.parse_args(args) activate_session(session, goptions) channels = session.listChannels() session.multicall = True for channel in channels: - session.listHosts(channelID=channel['id'], ready=options.ready, enabled=options.enabled) - for channel, hosts in zip(channels, session.multiCall()): - channel['hosts'] = len(hosts[0]) + session.listHosts(channelID=channel['id']) + for channel, [hosts] in zip(channels, session.multiCall()): + channel['enabled'] = len([x for x in hosts if x['enabled']]) + channel['disabled'] = len(hosts) - channel['enabled'] + channel['ready'] = len([x for x in hosts if x['ready']]) if not options.quiet: - print('Channel Hosts') + print('Channel Enb Rdy Dis') for channel in channels: - print("%(name)-15s %(hosts) 5d" % channel) + print("%(name)-15s %(enabled)5d %(ready)5d %(disabled)5d" % channel) def anon_handle_list_hosts(goptions, session, args): From ba6ceffdce8e1d6a65542c59677ecef8ed04c6fe Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 31 2018 06:42:19 +0000 Subject: [PATCH 3/3] fix test --- diff --git a/tests/test_cli/test_list_channels.py b/tests/test_cli/test_list_channels.py index 07f63e9..5a6e58b 100644 --- a/tests/test_cli/test_list_channels.py +++ b/tests/test_cli/test_list_channels.py @@ -22,11 +22,22 @@ class TestListChannels(unittest.TestCase): {'id': 1, 'name': 'default'}, {'id': 2, 'name': 'test'}, ] - self.session.multiCall.return_value = [[[1,2,3]], [[4,5]]] + self.session.multiCall.return_value = [ + [[ + {'enabled': True, 'ready': True}, + {'enabled': True, 'ready': False}, + {'enabled': True, 'ready': False}, + ]], + [[ + {'enabled': True, 'ready': True}, + {'enabled': False, 'ready': True}, + {'enabled': True, 'ready': False}, + ]], + ] anon_handle_list_channels(self.options, self.session, self.args) actual = stdout.getvalue() - expected = 'default 3\ntest 2\n' + expected = 'default 3 1 0\ntest 2 2 1\n' self.assertMultiLineEqual(actual, expected) activate_session_mock.assert_called_once_with(self.session, self.options)