Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 14390e3

Browse files
vrothberggregkh
authored andcommitted
checkkconfigsymbols: use ArgumentParser
Replace the deprecated OptionParser with ArgumentParser, as recommended by pylint. Signed-off-by: Valentin Rothberg <valentinrothberg@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7c5227a commit 14390e3

File tree

1 file changed

+69
-73
lines changed

1 file changed

+69
-73
lines changed

scripts/checkkconfigsymbols.py

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
# Licensed under the terms of the GNU GPL License version 2
99

1010

11+
import argparse
1112
import difflib
1213
import os
1314
import re
1415
import signal
1516
import subprocess
1617
import sys
1718
from multiprocessing import Pool, cpu_count
18-
from optparse import OptionParser
1919
from subprocess import Popen, PIPE, STDOUT
2020

2121

@@ -43,90 +43,86 @@
4343

4444
def parse_options():
4545
"""The user interface of this module."""
46-
usage = "%prog [options]\n\n" \
47-
"Run this tool to detect Kconfig symbols that are referenced but " \
48-
"not defined in\nKconfig. The output of this tool has the " \
49-
"format \'Undefined symbol\\tFile list\'\n\n" \
50-
"If no option is specified, %prog will default to check your\n" \
51-
"current tree. Please note that specifying commits will " \
52-
"\'git reset --hard\'\nyour current tree! You may save " \
53-
"uncommitted changes to avoid losing data."
54-
55-
parser = OptionParser(usage=usage)
56-
57-
parser.add_option('-c', '--commit', dest='commit', action='store',
58-
default="",
59-
help="Check if the specified commit (hash) introduces "
60-
"undefined Kconfig symbols.")
61-
62-
parser.add_option('-d', '--diff', dest='diff', action='store',
63-
default="",
64-
help="Diff undefined symbols between two commits. The "
65-
"input format bases on Git log's "
66-
"\'commmit1..commit2\'.")
67-
68-
parser.add_option('-f', '--find', dest='find', action='store_true',
69-
default=False,
70-
help="Find and show commits that may cause symbols to be "
71-
"missing. Required to run with --diff.")
72-
73-
parser.add_option('-i', '--ignore', dest='ignore', action='store',
74-
default="",
75-
help="Ignore files matching this pattern. Note that "
76-
"the pattern needs to be a Python regex. To "
77-
"ignore defconfigs, specify -i '.*defconfig'.")
78-
79-
parser.add_option('-s', '--sim', dest='sim', action='store', default="",
80-
help="Print a list of maximum 10 string-similar symbols.")
81-
82-
parser.add_option('', '--force', dest='force', action='store_true',
83-
default=False,
84-
help="Reset current Git tree even when it's dirty.")
85-
86-
parser.add_option('', '--no-color', dest='color', action='store_false',
87-
default=True,
88-
help="Don't print colored output. Default when not "
89-
"outputting to a terminal.")
90-
91-
(opts, _) = parser.parse_args()
92-
93-
if opts.commit and opts.diff:
46+
usage = "Run this tool to detect Kconfig symbols that are referenced but " \
47+
"not defined in Kconfig. If no option is specified, " \
48+
"checkkconfigsymbols defaults to check your current tree. " \
49+
"Please note that specifying commits will 'git reset --hard\' " \
50+
"your current tree! You may save uncommitted changes to avoid " \
51+
"losing data."
52+
53+
parser = argparse.ArgumentParser(description=usage)
54+
55+
parser.add_argument('-c', '--commit', dest='commit', action='store',
56+
default="",
57+
help="check if the specified commit (hash) introduces "
58+
"undefined Kconfig symbols")
59+
60+
parser.add_argument('-d', '--diff', dest='diff', action='store',
61+
default="",
62+
help="diff undefined symbols between two commits "
63+
"(e.g., -d commmit1..commit2)")
64+
65+
parser.add_argument('-f', '--find', dest='find', action='store_true',
66+
default=False,
67+
help="find and show commits that may cause symbols to be "
68+
"missing (required to run with --diff)")
69+
70+
parser.add_argument('-i', '--ignore', dest='ignore', action='store',
71+
default="",
72+
help="ignore files matching this Python regex "
73+
"(e.g., -i '.*defconfig')")
74+
75+
parser.add_argument('-s', '--sim', dest='sim', action='store', default="",
76+
help="print a list of max. 10 string-similar symbols")
77+
78+
parser.add_argument('--force', dest='force', action='store_true',
79+
default=False,
80+
help="reset current Git tree even when it's dirty")
81+
82+
parser.add_argument('--no-color', dest='color', action='store_false',
83+
default=True,
84+
help="don't print colored output (default when not "
85+
"outputting to a terminal)")
86+
87+
args = parser.parse_args()
88+
89+
if args.commit and args.diff:
9490
sys.exit("Please specify only one option at once.")
9591

96-
if opts.diff and not re.match(r"^[\w\-\.]+\.\.[\w\-\.]+$", opts.diff):
92+
if args.diff and not re.match(r"^[\w\-\.]+\.\.[\w\-\.]+$", args.diff):
9793
sys.exit("Please specify valid input in the following format: "
9894
"\'commit1..commit2\'")
9995

100-
if opts.commit or opts.diff:
101-
if not opts.force and tree_is_dirty():
96+
if args.commit or args.diff:
97+
if not args.force and tree_is_dirty():
10298
sys.exit("The current Git tree is dirty (see 'git status'). "
10399
"Running this script may\ndelete important data since it "
104100
"calls 'git reset --hard' for some performance\nreasons. "
105101
" Please run this script in a clean Git tree or pass "
106102
"'--force' if you\nwant to ignore this warning and "
107103
"continue.")
108104

109-
if opts.commit:
110-
opts.find = False
105+
if args.commit:
106+
args.find = False
111107

112-
if opts.ignore:
108+
if args.ignore:
113109
try:
114-
re.match(opts.ignore, "this/is/just/a/test.c")
110+
re.match(args.ignore, "this/is/just/a/test.c")
115111
except:
116112
sys.exit("Please specify a valid Python regex.")
117113

118-
return opts
114+
return args
119115

120116

121117
def main():
122118
"""Main function of this module."""
123-
opts = parse_options()
119+
args = parse_options()
124120

125121
global color
126-
color = opts.color and sys.stdout.isatty()
122+
color = args.color and sys.stdout.isatty()
127123

128-
if opts.sim and not opts.commit and not opts.diff:
129-
sims = find_sims(opts.sim, opts.ignore)
124+
if args.sim and not args.commit and not args.diff:
125+
sims = find_sims(args.sim, args.ignore)
130126
if sims:
131127
print("%s: %s" % (yel("Similar symbols"), ', '.join(sims)))
132128
else:
@@ -137,29 +133,29 @@ def main():
137133
defined = {}
138134
undefined = {}
139135

140-
if opts.commit or opts.diff:
136+
if args.commit or args.diff:
141137
head = get_head()
142138

143139
# get commit range
144140
commit_a = None
145141
commit_b = None
146-
if opts.commit:
147-
commit_a = opts.commit + "~"
148-
commit_b = opts.commit
149-
elif opts.diff:
150-
split = opts.diff.split("..")
142+
if args.commit:
143+
commit_a = args.commit + "~"
144+
commit_b = args.commit
145+
elif args.diff:
146+
split = args.diff.split("..")
151147
commit_a = split[0]
152148
commit_b = split[1]
153149
undefined_a = {}
154150
undefined_b = {}
155151

156152
# get undefined items before the commit
157153
execute("git reset --hard %s" % commit_a)
158-
undefined_a, _ = check_symbols(opts.ignore)
154+
undefined_a, _ = check_symbols(args.ignore)
159155

160156
# get undefined items for the commit
161157
execute("git reset --hard %s" % commit_b)
162-
undefined_b, defined = check_symbols(opts.ignore)
158+
undefined_b, defined = check_symbols(args.ignore)
163159

164160
# report cases that are present for the commit but not before
165161
for feature in sorted(undefined_b):
@@ -179,7 +175,7 @@ def main():
179175

180176
# default to check the entire tree
181177
else:
182-
undefined, defined = check_symbols(opts.ignore)
178+
undefined, defined = check_symbols(args.ignore)
183179

184180
# now print the output
185181
for feature in sorted(undefined):
@@ -188,16 +184,16 @@ def main():
188184
files = sorted(undefined.get(feature))
189185
print("%s: %s" % (yel("Referencing files"), ", ".join(files)))
190186

191-
sims = find_sims(feature, opts.ignore, defined)
187+
sims = find_sims(feature, args.ignore, defined)
192188
sims_out = yel("Similar symbols")
193189
if sims:
194190
print("%s: %s" % (sims_out, ', '.join(sims)))
195191
else:
196192
print("%s: %s" % (sims_out, "no similar symbols found"))
197193

198-
if opts.find:
194+
if args.find:
199195
print("%s:" % yel("Commits changing symbol"))
200-
commits = find_commits(feature, opts.diff)
196+
commits = find_commits(feature, args.diff)
201197
if commits:
202198
for commit in commits:
203199
commit = commit.split(" ", 1)

0 commit comments

Comments
 (0)