aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkkconfigsymbols.py
diff options
context:
space:
mode:
authorValentin Rothberg <valentinrothberg@gmail.com>2016-08-28 02:51:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-08-28 05:08:34 -0400
commit14390e31641e6fb482ad75b7f46bc54d798f8b87 (patch)
tree6748168846fff37993eed2bb72a2788d10844073 /scripts/checkkconfigsymbols.py
parent7c5227af25a1bee7c577162bd55600dae8023f5a (diff)
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>
Diffstat (limited to 'scripts/checkkconfigsymbols.py')
-rwxr-xr-xscripts/checkkconfigsymbols.py142
1 files changed, 69 insertions, 73 deletions
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
index 2b13d8a5c0f6..322c5e817b4c 100755
--- a/scripts/checkkconfigsymbols.py
+++ b/scripts/checkkconfigsymbols.py
@@ -8,6 +8,7 @@
8# Licensed under the terms of the GNU GPL License version 2 8# Licensed under the terms of the GNU GPL License version 2
9 9
10 10
11import argparse
11import difflib 12import difflib
12import os 13import os
13import re 14import re
@@ -15,7 +16,6 @@ import signal
15import subprocess 16import subprocess
16import sys 17import sys
17from multiprocessing import Pool, cpu_count 18from multiprocessing import Pool, cpu_count
18from optparse import OptionParser
19from subprocess import Popen, PIPE, STDOUT 19from subprocess import Popen, PIPE, STDOUT
20 20
21 21
@@ -43,62 +43,58 @@ REGEX_QUOTES = re.compile("(\"(.*?)\")")
43 43
44def parse_options(): 44def parse_options():
45 """The user interface of this module.""" 45 """The user interface of this module."""
46 usage = "%prog [options]\n\n" \ 46 usage = "Run this tool to detect Kconfig symbols that are referenced but " \
47 "Run this tool to detect Kconfig symbols that are referenced but " \ 47 "not defined in Kconfig. If no option is specified, " \
48 "not defined in\nKconfig. The output of this tool has the " \ 48 "checkkconfigsymbols defaults to check your current tree. " \
49 "format \'Undefined symbol\\tFile list\'\n\n" \ 49 "Please note that specifying commits will 'git reset --hard\' " \
50 "If no option is specified, %prog will default to check your\n" \ 50 "your current tree! You may save uncommitted changes to avoid " \
51 "current tree. Please note that specifying commits will " \ 51 "losing data."
52 "\'git reset --hard\'\nyour current tree! You may save " \ 52
53 "uncommitted changes to avoid losing data." 53 parser = argparse.ArgumentParser(description=usage)
54 54
55 parser = OptionParser(usage=usage) 55 parser.add_argument('-c', '--commit', dest='commit', action='store',
56 56 default="",
57 parser.add_option('-c', '--commit', dest='commit', action='store', 57 help="check if the specified commit (hash) introduces "
58 default="", 58 "undefined Kconfig symbols")
59 help="Check if the specified commit (hash) introduces " 59
60 "undefined Kconfig symbols.") 60 parser.add_argument('-d', '--diff', dest='diff', action='store',
61 61 default="",
62 parser.add_option('-d', '--diff', dest='diff', action='store', 62 help="diff undefined symbols between two commits "
63 default="", 63 "(e.g., -d commmit1..commit2)")
64 help="Diff undefined symbols between two commits. The " 64
65 "input format bases on Git log's " 65 parser.add_argument('-f', '--find', dest='find', action='store_true',
66 "\'commmit1..commit2\'.") 66 default=False,
67 67 help="find and show commits that may cause symbols to be "
68 parser.add_option('-f', '--find', dest='find', action='store_true', 68 "missing (required to run with --diff)")
69 default=False, 69
70 help="Find and show commits that may cause symbols to be " 70 parser.add_argument('-i', '--ignore', dest='ignore', action='store',
71 "missing. Required to run with --diff.") 71 default="",
72 72 help="ignore files matching this Python regex "
73 parser.add_option('-i', '--ignore', dest='ignore', action='store', 73 "(e.g., -i '.*defconfig')")
74 default="", 74
75 help="Ignore files matching this pattern. Note that " 75 parser.add_argument('-s', '--sim', dest='sim', action='store', default="",
76 "the pattern needs to be a Python regex. To " 76 help="print a list of max. 10 string-similar symbols")
77 "ignore defconfigs, specify -i '.*defconfig'.") 77
78 78 parser.add_argument('--force', dest='force', action='store_true',
79 parser.add_option('-s', '--sim', dest='sim', action='store', default="", 79 default=False,
80 help="Print a list of maximum 10 string-similar symbols.") 80 help="reset current Git tree even when it's dirty")
81 81
82 parser.add_option('', '--force', dest='force', action='store_true', 82 parser.add_argument('--no-color', dest='color', action='store_false',
83 default=False, 83 default=True,
84 help="Reset current Git tree even when it's dirty.") 84 help="don't print colored output (default when not "
85 85 "outputting to a terminal)")
86 parser.add_option('', '--no-color', dest='color', action='store_false', 86
87 default=True, 87 args = parser.parse_args()
88 help="Don't print colored output. Default when not " 88
89 "outputting to a terminal.") 89 if args.commit and args.diff:
90
91 (opts, _) = parser.parse_args()
92
93 if opts.commit and opts.diff:
94 sys.exit("Please specify only one option at once.") 90 sys.exit("Please specify only one option at once.")
95 91
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):
97 sys.exit("Please specify valid input in the following format: " 93 sys.exit("Please specify valid input in the following format: "
98 "\'commit1..commit2\'") 94 "\'commit1..commit2\'")
99 95
100 if opts.commit or opts.diff: 96 if args.commit or args.diff:
101 if not opts.force and tree_is_dirty(): 97 if not args.force and tree_is_dirty():
102 sys.exit("The current Git tree is dirty (see 'git status'). " 98 sys.exit("The current Git tree is dirty (see 'git status'). "
103 "Running this script may\ndelete important data since it " 99 "Running this script may\ndelete important data since it "
104 "calls 'git reset --hard' for some performance\nreasons. " 100 "calls 'git reset --hard' for some performance\nreasons. "
@@ -106,27 +102,27 @@ def parse_options():
106 "'--force' if you\nwant to ignore this warning and " 102 "'--force' if you\nwant to ignore this warning and "
107 "continue.") 103 "continue.")
108 104
109 if opts.commit: 105 if args.commit:
110 opts.find = False 106 args.find = False
111 107
112 if opts.ignore: 108 if args.ignore:
113 try: 109 try:
114 re.match(opts.ignore, "this/is/just/a/test.c") 110 re.match(args.ignore, "this/is/just/a/test.c")
115 except: 111 except:
116 sys.exit("Please specify a valid Python regex.") 112 sys.exit("Please specify a valid Python regex.")
117 113
118 return opts 114 return args
119 115
120 116
121def main(): 117def main():
122 """Main function of this module.""" 118 """Main function of this module."""
123 opts = parse_options() 119 args = parse_options()
124 120
125 global color 121 global color
126 color = opts.color and sys.stdout.isatty() 122 color = args.color and sys.stdout.isatty()
127 123
128 if opts.sim and not opts.commit and not opts.diff: 124 if args.sim and not args.commit and not args.diff:
129 sims = find_sims(opts.sim, opts.ignore) 125 sims = find_sims(args.sim, args.ignore)
130 if sims: 126 if sims:
131 print("%s: %s" % (yel("Similar symbols"), ', '.join(sims))) 127 print("%s: %s" % (yel("Similar symbols"), ', '.join(sims)))
132 else: 128 else:
@@ -137,17 +133,17 @@ def main():
137 defined = {} 133 defined = {}
138 undefined = {} 134 undefined = {}
139 135
140 if opts.commit or opts.diff: 136 if args.commit or args.diff:
141 head = get_head() 137 head = get_head()
142 138
143 # get commit range 139 # get commit range
144 commit_a = None 140 commit_a = None
145 commit_b = None 141 commit_b = None
146 if opts.commit: 142 if args.commit:
147 commit_a = opts.commit + "~" 143 commit_a = args.commit + "~"
148 commit_b = opts.commit 144 commit_b = args.commit
149 elif opts.diff: 145 elif args.diff:
150 split = opts.diff.split("..") 146 split = args.diff.split("..")
151 commit_a = split[0] 147 commit_a = split[0]
152 commit_b = split[1] 148 commit_b = split[1]
153 undefined_a = {} 149 undefined_a = {}
@@ -155,11 +151,11 @@ def main():
155 151
156 # get undefined items before the commit 152 # get undefined items before the commit
157 execute("git reset --hard %s" % commit_a) 153 execute("git reset --hard %s" % commit_a)
158 undefined_a, _ = check_symbols(opts.ignore) 154 undefined_a, _ = check_symbols(args.ignore)
159 155
160 # get undefined items for the commit 156 # get undefined items for the commit
161 execute("git reset --hard %s" % commit_b) 157 execute("git reset --hard %s" % commit_b)
162 undefined_b, defined = check_symbols(opts.ignore) 158 undefined_b, defined = check_symbols(args.ignore)
163 159
164 # report cases that are present for the commit but not before 160 # report cases that are present for the commit but not before
165 for feature in sorted(undefined_b): 161 for feature in sorted(undefined_b):
@@ -179,7 +175,7 @@ def main():
179 175
180 # default to check the entire tree 176 # default to check the entire tree
181 else: 177 else:
182 undefined, defined = check_symbols(opts.ignore) 178 undefined, defined = check_symbols(args.ignore)
183 179
184 # now print the output 180 # now print the output
185 for feature in sorted(undefined): 181 for feature in sorted(undefined):
@@ -188,16 +184,16 @@ def main():
188 files = sorted(undefined.get(feature)) 184 files = sorted(undefined.get(feature))
189 print("%s: %s" % (yel("Referencing files"), ", ".join(files))) 185 print("%s: %s" % (yel("Referencing files"), ", ".join(files)))
190 186
191 sims = find_sims(feature, opts.ignore, defined) 187 sims = find_sims(feature, args.ignore, defined)
192 sims_out = yel("Similar symbols") 188 sims_out = yel("Similar symbols")
193 if sims: 189 if sims:
194 print("%s: %s" % (sims_out, ', '.join(sims))) 190 print("%s: %s" % (sims_out, ', '.join(sims)))
195 else: 191 else:
196 print("%s: %s" % (sims_out, "no similar symbols found")) 192 print("%s: %s" % (sims_out, "no similar symbols found"))
197 193
198 if opts.find: 194 if args.find:
199 print("%s:" % yel("Commits changing symbol")) 195 print("%s:" % yel("Commits changing symbol"))
200 commits = find_commits(feature, opts.diff) 196 commits = find_commits(feature, args.diff)
201 if commits: 197 if commits:
202 for commit in commits: 198 for commit in commits:
203 commit = commit.split(" ", 1) 199 commit = commit.split(" ", 1)