diff options
author | Simon Glass <sjg@chromium.org> | 2020-07-05 21:41:53 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-07-24 19:25:15 -0600 |
commit | fda1e372d35dc956317923f5057c3ac83be7f571 (patch) | |
tree | c019d16ce2ec2346ccf55d80b50304f5ae396f21 /tools/patman/main.py | |
parent | 137947e05b25a9e511bbc30bd795c9d95deec0cb (diff) | |
download | u-boot-fda1e372d35dc956317923f5057c3ac83be7f571.tar.gz |
patman: Convert to ArgumentParser
Convert from OptionParser to ArgumentParser to match binman. With this we
can easily add sub-commands.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/patman/main.py')
-rwxr-xr-x | tools/patman/main.py | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/tools/patman/main.py b/tools/patman/main.py index 4d7a3044ea..34cad9a562 100755 --- a/tools/patman/main.py +++ b/tools/patman/main.py @@ -6,7 +6,7 @@ """See README for more information""" -from optparse import OptionParser +from argparse import ArgumentParser import os import re import sys @@ -27,71 +27,70 @@ from patman import terminal from patman import test_util from patman import test_checkpatch +epilog = '''Create patches from commits in a branch, check them and email them +as specified by tags you place in the commits. Use -n to do a dry run first.''' -parser = OptionParser() -parser.add_option('-H', '--full-help', action='store_true', dest='full_help', +parser = ArgumentParser(epilog=epilog) +parser.add_argument('-H', '--full-help', action='store_true', dest='full_help', default=False, help='Display the README file') -parser.add_option('-b', '--branch', type='str', +parser.add_argument('-b', '--branch', type=str, help="Branch to process (by default, the current branch)") -parser.add_option('-c', '--count', dest='count', type='int', +parser.add_argument('-c', '--count', dest='count', type=int, default=-1, help='Automatically create patches from top n commits') -parser.add_option('-e', '--end', type='int', default=0, +parser.add_argument('-e', '--end', type=int, default=0, help='Commits to skip at end of patch list') -parser.add_option('-i', '--ignore-errors', action='store_true', +parser.add_argument('-i', '--ignore-errors', action='store_true', dest='ignore_errors', default=False, help='Send patches email even if patch errors are found') -parser.add_option('-l', '--limit-cc', dest='limit', type='int', - default=None, help='Limit the cc list to LIMIT entries [default: %default]') -parser.add_option('-m', '--no-maintainers', action='store_false', +parser.add_argument('-l', '--limit-cc', dest='limit', type=int, default=None, + help='Limit the cc list to LIMIT entries [default: %(default)]') +parser.add_argument('-m', '--no-maintainers', action='store_false', dest='add_maintainers', default=True, help="Don't cc the file maintainers automatically") -parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run', +parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', default=False, help="Do a dry run (create but don't email patches)") -parser.add_option('-p', '--project', default=project.DetectProject(), - help="Project name; affects default option values and " - "aliases [default: %default]") -parser.add_option('-r', '--in-reply-to', type='string', action='store', +parser.add_argument('-p', '--project', default=project.DetectProject(), + help="Project name; affects default option values and " + "aliases [default: %(default)]") +parser.add_argument('-r', '--in-reply-to', type=str, action='store', help="Message ID that this series is in reply to") -parser.add_option('-s', '--start', dest='start', type='int', +parser.add_argument('-s', '--start', dest='start', type=int, default=0, help='Commit to start creating patches from (0 = HEAD)') -parser.add_option('-t', '--ignore-bad-tags', action='store_true', - default=False, help='Ignore bad tags / aliases') -parser.add_option('-v', '--verbose', action='store_true', dest='verbose', +parser.add_argument('-t', '--ignore-bad-tags', action='store_true', + default=False, help='Ignore bad tags / aliases') +parser.add_argument('-v', '--verbose', action='store_true', dest='verbose', default=False, help='Verbose output of errors and warnings') -parser.add_option('-T', '--thread', action='store_true', dest='thread', - default=False, help='Create patches as a single thread') -parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store', +parser.add_argument('-T', '--thread', action='store_true', dest='thread', + default=False, help='Create patches as a single thread') +parser.add_argument('--cc-cmd', dest='cc_cmd', type=str, action='store', default=None, help='Output cc list for patch file (used by git)') -parser.add_option('--no-binary', action='store_true', dest='ignore_binary', - default=False, - help="Do not output contents of changes in binary files") -parser.add_option('--no-check', action='store_false', dest='check_patch', - default=True, - help="Don't check for patch compliance") -parser.add_option('--no-tags', action='store_false', dest='process_tags', - default=True, help="Don't process subject tags as aliases") -parser.add_option('--smtp-server', type='str', - help="Specify the SMTP server to 'git send-email'") -parser.add_option('--test', action='store_true', dest='test', - default=False, help='run tests') - -parser.usage += """ - -Create patches from commits in a branch, check them and email them as -specified by tags you place in the commits. Use -n to do a dry run first.""" - +parser.add_argument('--no-binary', action='store_true', dest='ignore_binary', + default=False, + help="Do not output contents of changes in binary files") +parser.add_argument('--no-check', action='store_false', dest='check_patch', + default=True, + help="Don't check for patch compliance") +parser.add_argument('--no-tags', action='store_false', dest='process_tags', + default=True, help="Don't process subject tags as aliases") +parser.add_argument('--smtp-server', type=str, + help="Specify the SMTP server to 'git send-email'") +parser.add_argument('--test', action='store_true', dest='test', + default=False, help='run tests') + +parser.add_argument('patchfiles', nargs='*') # Parse options twice: first to get the project and second to handle # defaults properly (which depends on project). -(options, args) = parser.parse_args() -settings.Setup(gitutil, parser, options.project, '') -(options, args) = parser.parse_args() +argv = sys.argv[1:] +args = parser.parse_args(argv) +settings.Setup(gitutil, parser, args.project, '') +args = parser.parse_args(argv) if __name__ != "__main__": pass # Run our meagre tests -elif options.test: +elif args.test: import doctest from patman import func_test @@ -109,19 +108,19 @@ elif options.test: # Called from git with a patch filename as argument # Printout a list of additional CC recipients for this patch -elif options.cc_cmd: - fd = open(options.cc_cmd, 'r') +elif args.cc_cmd: + fd = open(args.cc_cmd, 'r') re_line = re.compile('(\S*) (.*)') for line in fd.readlines(): match = re_line.match(line) - if match and match.group(1) == args[0]: + if match and match.group(1) == args.patchfiles[0]: for cc in match.group(2).split('\0'): cc = cc.strip() if cc: print(cc) fd.close() -elif options.full_help: +elif args.full_help: pager = os.getenv('PAGER') if not pager: pager = 'more' @@ -131,4 +130,4 @@ elif options.full_help: # Process commits, produce patches files, check them, email them else: - control.send(options) + control.send(args) |