From a87c6aedbe33b185b9f844b3b19fdbb9a00bca58 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Thu, 6 Apr 2023 13:11:19 +0200 Subject: [PATCH] Add component/built archives in list-buildroot Fixes: https://pagure.io/koji/issue/3759 --- cli/koji_cli/commands.py | 25 +++++++-- tests/test_cli/test_list_buildroot.py | 75 +++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 87e5c698..e4806a18 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2785,7 +2785,7 @@ def anon_handle_list_buildroot(goptions, session, args): "[info] List the rpms used in or built in a buildroot" usage = "usage: %prog list-buildroot [options] " parser = OptionParser(usage=get_usage_str(usage)) - parser.add_option("--built", action="store_true", help="Show the built rpms") + parser.add_option("--built", action="store_true", help="Show the built rpms and archives") parser.add_option("--verbose", "-v", action="store_true", help="Show more information") (options, args) = parser.parse_args(args) if len(args) != 1: @@ -2797,16 +2797,35 @@ def anon_handle_list_buildroot(goptions, session, args): opts['buildrootID'] = buildrootID else: opts['componentBuildrootID'] = buildrootID - data = session.listRPMs(**opts) + + list_rpms = session.listRPMs(**opts) + if list_rpms: + if options.built: + print('Built RPMs:') + else: + print('Component RPMs:') fmt = "%(nvr)s.%(arch)s" - order = sorted([(fmt % x, x) for x in data]) + order = sorted([(fmt % x, x) for x in list_rpms]) for nvra, rinfo in order: if options.verbose and rinfo.get('is_update'): print("%s [update]" % nvra) else: print(nvra) + list_archives = session.listArchives(**opts) + if list_archives: + if list_rpms: + # print empty line between list of RPMs and archives + print('') + if options.built: + print('Built Archives:') + else: + print('Component Archives:') + order = sorted([x['filename'] for x in list_archives]) + for filename in order: + print(filename) + def anon_handle_list_untagged(goptions, session, args): "[info] List untagged builds" diff --git a/tests/test_cli/test_list_buildroot.py b/tests/test_cli/test_list_buildroot.py index 54c8a98e..7b4b6ce7 100644 --- a/tests/test_cli/test_list_buildroot.py +++ b/tests/test_cli/test_list_buildroot.py @@ -33,8 +33,9 @@ class TestListBuilds(utils.CliTestCase): self.session.listRPMs.assert_not_called() @mock.patch('sys.stdout', new_callable=StringIO) - def test_list_buildroot_with_verbose(self, stdout): - expected_output = """testpackage-1.1-7.f33.noarch + def test_list_buildroot_with_verbose_with_rpms_without_archives(self, stdout): + expected_output = """Component RPMs: +testpackage-1.1-7.f33.noarch testpkg-1.171-5.fc33.noarch [update] tpkg-4.11-1.fc33.x86_64 [update] """ @@ -42,15 +43,60 @@ tpkg-4.11-1.fc33.x86_64 [update] {'arch': 'noarch', 'is_update': False, 'nvr': 'testpackage-1.1-7.f33'}, {'arch': 'x86_64', 'is_update': True, 'nvr': 'tpkg-4.11-1.fc33'}] self.session.listRPMs.return_value = list_rpms + self.session.listArchives.return_value = [] rv = anon_handle_list_buildroot(self.options, self.session, ['--verbose', '1']) self.assertEqual(rv, None) self.assert_console_message(stdout, expected_output) self.ensure_connection_mock.assert_called_once_with(self.session, self.options) self.session.listRPMs.assert_called_once_with(componentBuildrootID=1) + self.session.listArchives.assert_called_once_with(componentBuildrootID=1) @mock.patch('sys.stdout', new_callable=StringIO) - def test_list_buildroot_with_built(self, stdout): - expected_output = """testpackage-1.1-7.f33.x86_64 + def test_list_buildroot_with_verbose_without_rpms_with_archives(self, stdout): + expected_output = """Component Archives: +archivename1.tar.gz +archivename2.zip +""" + list_archives = [{'filename': 'archivename2.zip'}, + {'filename': 'archivename1.tar.gz'}] + self.session.listRPMs.return_value = [] + self.session.listArchives.return_value = list_archives + rv = anon_handle_list_buildroot(self.options, self.session, ['--verbose', '1']) + self.assertEqual(rv, None) + self.assert_console_message(stdout, expected_output) + self.ensure_connection_mock.assert_called_once_with(self.session, self.options) + self.session.listRPMs.assert_called_once_with(componentBuildrootID=1) + self.session.listArchives.assert_called_once_with(componentBuildrootID=1) + + @mock.patch('sys.stdout', new_callable=StringIO) + def test_list_buildroot_with_verbose_with_rpms_with_archives(self, stdout): + expected_output = """Component RPMs: +testpackage-1.1-7.f33.noarch +testpkg-1.171-5.fc33.noarch [update] +tpkg-4.11-1.fc33.x86_64 [update] + +Component Archives: +archivename1.tar.gz +archivename2.zip +""" + list_rpms = [{'arch': 'noarch', 'is_update': True, 'nvr': 'testpkg-1.171-5.fc33'}, + {'arch': 'noarch', 'is_update': False, 'nvr': 'testpackage-1.1-7.f33'}, + {'arch': 'x86_64', 'is_update': True, 'nvr': 'tpkg-4.11-1.fc33'}] + list_archives = [{'filename': 'archivename2.zip'}, + {'filename': 'archivename1.tar.gz'}] + self.session.listRPMs.return_value = list_rpms + self.session.listArchives.return_value = list_archives + rv = anon_handle_list_buildroot(self.options, self.session, ['--verbose', '1']) + self.assertEqual(rv, None) + self.assert_console_message(stdout, expected_output) + self.ensure_connection_mock.assert_called_once_with(self.session, self.options) + self.session.listRPMs.assert_called_once_with(componentBuildrootID=1) + self.session.listArchives.assert_called_once_with(componentBuildrootID=1) + + @mock.patch('sys.stdout', new_callable=StringIO) + def test_list_buildroot_with_built_with_rpms_without_archives(self, stdout): + expected_output = """Built RPMs: +testpackage-1.1-7.f33.x86_64 testpkg-1.171-5.fc33.noarch tpkg-4.11-1.fc33.noarch """ @@ -58,11 +104,30 @@ tpkg-4.11-1.fc33.noarch {'arch': 'x86_64', 'nvr': 'testpackage-1.1-7.f33'}, {'arch': 'noarch', 'nvr': 'tpkg-4.11-1.fc33'}] self.session.listRPMs.return_value = list_rpms + self.session.listArchives.return_value = [] rv = anon_handle_list_buildroot(self.options, self.session, ['--built', '2']) self.assertEqual(rv, None) self.assert_console_message(stdout, expected_output) self.ensure_connection_mock.assert_called_once_with(self.session, self.options) self.session.listRPMs.assert_called_once_with(buildrootID=2) + self.session.listArchives.assert_called_once_with(buildrootID=2) + + @mock.patch('sys.stdout', new_callable=StringIO) + def test_list_buildroot_with_built_without_rpms_with_archives(self, stdout): + expected_output = """Built Archives: +archivename1.tar.gz +archivename2.zip +""" + list_archives = [{'filename': 'archivename2.zip'}, + {'filename': 'archivename1.tar.gz'}] + self.session.listRPMs.return_value = [] + self.session.listArchives.return_value = list_archives + rv = anon_handle_list_buildroot(self.options, self.session, ['--built', '2']) + self.assertEqual(rv, None) + self.assert_console_message(stdout, expected_output) + self.ensure_connection_mock.assert_called_once_with(self.session, self.options) + self.session.listRPMs.assert_called_once_with(buildrootID=2) + self.session.listArchives.assert_called_once_with(buildrootID=2) def test_list_buildroot_help(self): self.assert_help( @@ -72,7 +137,7 @@ tpkg-4.11-1.fc33.noarch Options: -h, --help show this help message and exit - --built Show the built rpms + --built Show the built rpms and archives -v, --verbose Show more information """ % self.progname) self.ensure_connection_mock.assert_not_called()