From 4bf09bd398fc97148b35945962fa8c1db1f90624 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mon, 9 Mar 2020 15:03:29 +0100 Subject: [PATCH 1/4] Better help for build/latest-build People can be confused by buildtag/desttag/target. Shed some light in these commands' helps. Fixes: https://pagure.io/koji/issue/1808 --- cli/koji_cli/commands.py | 27 ++++++++++++++-- tests/test_cli/test_build.py | 60 ++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index f831097e..31d50aae 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -11,6 +11,7 @@ import random import re import stat import sys +import textwrap import time import traceback from collections import OrderedDict, defaultdict @@ -454,7 +455,20 @@ def handle_remove_pkg(goptions, session, args): def handle_build(options, session, args): "[build] Build a package from source" - usage = _("usage: %prog build [options] ") + + usage = _("""\ + usage: %prog build [options] + + First option is build target (don't confuse it with destination + tag (where build ends) or buildroot (from where dependencies + are installed). + + List of all available targets can be acquired by " + 'koji list-targets'. For further info about how tags, targets " + and buildroot interact, check the " + https://docs.pagure.org/koji/HOWTO/#package-organization""") + + usage = textwrap.dedent(usage) parser = OptionParser(usage=get_usage_str(usage)) parser.add_option("--skip-tag", action="store_true", help=_("Do not attempt to tag package")) @@ -2334,8 +2348,15 @@ def handle_revoke_cg_access(goptions, session, args): def anon_handle_latest_build(goptions, session, args): - "[info] Print the latest builds for a tag" - usage = _("usage: %prog latest-build [options] [ ...]") + """[info] Print the latest builds for a tag""" + usage = _("""\ + usage: %prog latest-build [options] [ ...] + + Note, that needn't be same as build target. If you've wanted to + see what was the latest build in given buildroot, check '%prog + list-targets --name=' to find name of the buildroot's tag""") + + usage = textwrap.dedent(usage) parser = OptionParser(usage=get_usage_str(usage)) parser.add_option("--arch", help=_("List all of the latest packages for this arch")) parser.add_option("--all", action="store_true", diff --git a/tests/test_cli/test_build.py b/tests/test_cli/test_build.py index 101afd6a..6ee45189 100644 --- a/tests/test_cli/test_build.py +++ b/tests/test_cli/test_build.py @@ -3,14 +3,11 @@ import mock import os import six import sys -try: - import unittest2 as unittest -except ImportError: - import unittest from koji_cli.commands import handle_build, _progress_callback +from . import utils -class TestBuild(unittest.TestCase): +class TestBuild(utils.CliTestCase): # Show long diffs in error output... maxDiff = None @@ -22,6 +19,20 @@ class TestBuild(unittest.TestCase): self.options.poll_interval = 0 # Mock out the xmlrpc server self.session = mock.MagicMock() + self.error_format = """Usage: %s build [options] + +First option is build target (don't confuse it with destination +tag (where build ends) or buildroot (from where dependencies +are installed). + +List of all available targets can be acquired by " +'koji list-targets'. For further info about how tags, targets " +and buildroot interact, check the " +https://docs.pagure.org/koji/HOWTO/#package-organization +(Specify the --help global option for a list of other help options) + +%s: error: {message} +""" % (self.progname, self.progname) @mock.patch('sys.stdout', new_callable=six.StringIO) @mock.patch('koji_cli.commands.activate_session') @@ -147,11 +158,7 @@ Task info: weburl/taskinfo?taskID=1 actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = '' - expected_stderr = """Usage: %s build [options] -(Specify the --help global option for a list of other help options) - -%s: error: Exactly two arguments (a build target and a SCM URL or srpm file) are required -""" % (progname, progname) + expected_stderr = self.format_error_message("Exactly two arguments (a build target and a SCM URL or srpm file) are required") self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr) @@ -193,6 +200,15 @@ Task info: weburl/taskinfo?taskID=1 actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = """Usage: %s build [options] + +First option is build target (don't confuse it with destination +tag (where build ends) or buildroot (from where dependencies +are installed). + +List of all available targets can be acquired by " +'koji list-targets'. For further info about how tags, targets " +and buildroot interact, check the " +https://docs.pagure.org/koji/HOWTO/#package-organization (Specify the --help global option for a list of other help options) Options: @@ -259,11 +275,7 @@ Options: actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = '' - expected_stderr = """Usage: %s build [options] -(Specify the --help global option for a list of other help options) - -%s: error: --arch_override is only allowed for --scratch builds -""" % (progname, progname) + expected_stderr = self.format_error_message("--arch_override is only allowed for --scratch builds") self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr) @@ -354,11 +366,7 @@ Task info: weburl/taskinfo?taskID=1 with self.assertRaises(SystemExit) as cm: handle_build(self.options, self.session, args) actual = stderr.getvalue() - expected = """Usage: %s build [options] -(Specify the --help global option for a list of other help options) - -%s: error: Unknown build target: target -""" % (progname, progname) + expected = self.format_error_message( "Unknown build target: target") self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(self.session, self.options) @@ -405,11 +413,7 @@ Task info: weburl/taskinfo?taskID=1 with self.assertRaises(SystemExit) as cm: handle_build(self.options, self.session, args) actual = stderr.getvalue() - expected = """Usage: %s build [options] -(Specify the --help global option for a list of other help options) - -%s: error: Unknown destination tag: dest_tag_name -""" % (progname, progname) + expected = self.format_error_message("Unknown destination tag: dest_tag_name") self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(self.session, self.options) @@ -456,11 +460,7 @@ Task info: weburl/taskinfo?taskID=1 with self.assertRaises(SystemExit) as cm: handle_build(self.options, self.session, args) actual = stderr.getvalue() - expected = """Usage: %s build [options] -(Specify the --help global option for a list of other help options) - -%s: error: Destination tag dest_tag_name is locked -""" % (progname, progname) + expected = self.format_error_message("Destination tag dest_tag_name is locked") self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(self.session, self.options) From b17690201359f850308f8193d98cc14d42094f91 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Wed, 1 Apr 2020 13:20:40 +0200 Subject: [PATCH 2/4] fix grammar --- cli/koji_cli/commands.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 31d50aae..55244bdf 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -459,13 +459,12 @@ def handle_build(options, session, args): usage = _("""\ usage: %prog build [options] - First option is build target (don't confuse it with destination - tag (where build ends) or buildroot (from where dependencies - are installed). + The first option is the build target, not to be confused with the destination + tag (where the build eventually lands) or build tag (where the buildroot + contents are pulled from). - List of all available targets can be acquired by " - 'koji list-targets'. For further info about how tags, targets " - and buildroot interact, check the " + You can list all available build targets using the 'koji list-targets' command. + More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization""") usage = textwrap.dedent(usage) From 21b461ec258f2a90c6bba231ebc8596dca434c85 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Wed, 1 Apr 2020 13:28:01 +0200 Subject: [PATCH 3/4] fix test --- tests/test_cli/test_build.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/test_cli/test_build.py b/tests/test_cli/test_build.py index 6ee45189..b99cf2d2 100644 --- a/tests/test_cli/test_build.py +++ b/tests/test_cli/test_build.py @@ -21,13 +21,12 @@ class TestBuild(utils.CliTestCase): self.session = mock.MagicMock() self.error_format = """Usage: %s build [options] -First option is build target (don't confuse it with destination -tag (where build ends) or buildroot (from where dependencies -are installed). +The first option is the build target, not to be confused with the destination +tag (where the build eventually lands) or build tag (where the buildroot +contents are pulled from). -List of all available targets can be acquired by " -'koji list-targets'. For further info about how tags, targets " -and buildroot interact, check the " +You can list all available build targets using the 'koji list-targets' command. +More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization (Specify the --help global option for a list of other help options) @@ -201,13 +200,12 @@ Task info: weburl/taskinfo?taskID=1 actual_stderr = stderr.getvalue() expected_stdout = """Usage: %s build [options] -First option is build target (don't confuse it with destination -tag (where build ends) or buildroot (from where dependencies -are installed). +The first option is the build target, not to be confused with the destination +tag (where the build eventually lands) or build tag (where the buildroot +contents are pulled from). -List of all available targets can be acquired by " -'koji list-targets'. For further info about how tags, targets " -and buildroot interact, check the " +You can list all available build targets using the 'koji list-targets' command. +More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization (Specify the --help global option for a list of other help options) From 067d30080e26692d4526a3427eadd028bb7930b6 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Wed, 1 Apr 2020 17:03:53 -0400 Subject: [PATCH 4/4] more grammar changes --- cli/koji_cli/commands.py | 12 ++++++++---- tests/test_cli/test_build.py | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 55244bdf..88807328 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -463,7 +463,7 @@ def handle_build(options, session, args): tag (where the build eventually lands) or build tag (where the buildroot contents are pulled from). - You can list all available build targets using the 'koji list-targets' command. + You can list all available build targets using the '%prog list-targets' command. More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization""") @@ -2351,9 +2351,13 @@ def anon_handle_latest_build(goptions, session, args): usage = _("""\ usage: %prog latest-build [options] [ ...] - Note, that needn't be same as build target. If you've wanted to - see what was the latest build in given buildroot, check '%prog - list-targets --name=' to find name of the buildroot's tag""") + The first option should be the name of a tag, not the name of a build target. + If you want to know the latest build in buildroots for a given build target, + then you should use the name of the build tag for that target. You can find + this value by running '%prog list-targets --name=' + + More information on tags and build targets can be found in the documentation. + https://docs.pagure.org/koji/HOWTO/#package-organization""") usage = textwrap.dedent(usage) parser = OptionParser(usage=get_usage_str(usage)) diff --git a/tests/test_cli/test_build.py b/tests/test_cli/test_build.py index b99cf2d2..07669168 100644 --- a/tests/test_cli/test_build.py +++ b/tests/test_cli/test_build.py @@ -25,13 +25,13 @@ The first option is the build target, not to be confused with the destination tag (where the build eventually lands) or build tag (where the buildroot contents are pulled from). -You can list all available build targets using the 'koji list-targets' command. +You can list all available build targets using the '%s list-targets' command. More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization (Specify the --help global option for a list of other help options) %s: error: {message} -""" % (self.progname, self.progname) +""" % (self.progname, self.progname, self.progname) @mock.patch('sys.stdout', new_callable=six.StringIO) @mock.patch('koji_cli.commands.activate_session') @@ -204,7 +204,7 @@ The first option is the build target, not to be confused with the destination tag (where the build eventually lands) or build tag (where the buildroot contents are pulled from). -You can list all available build targets using the 'koji list-targets' command. +You can list all available build targets using the '%s list-targets' command. More detail can be found in the documentation. https://docs.pagure.org/koji/HOWTO/#package-organization (Specify the --help global option for a list of other help options) @@ -227,7 +227,7 @@ Options: --repo-id=REPO_ID Use a specific repo --noprogress Do not display progress of the upload --background Run the build at a lower priority -""" % progname +""" % (progname, progname) expected_stderr = '' self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr)