diff options
author | Valentin Rothberg <valentinrothberg@gmail.com> | 2016-08-28 02:51:28 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-08-28 05:08:34 -0400 |
commit | 7c5227af25a1bee7c577162bd55600dae8023f5a (patch) | |
tree | aeab3ea04039b6bf87abe9afcba9631aaeac413e /scripts/checkkconfigsymbols.py | |
parent | f175ba174ef3cb8c26e828c710e4e3b0f2bbbf55 (diff) |
checkkconfigsymbols.py: port to Python 3
Python 2 is slowly dying, so port the script to Python 3.
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-x | scripts/checkkconfigsymbols.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py index 0cae73b5c925..2b13d8a5c0f6 100755 --- a/scripts/checkkconfigsymbols.py +++ b/scripts/checkkconfigsymbols.py | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/usr/bin/env python2 | 1 | #!/usr/bin/env python3 |
2 | 2 | ||
3 | """Find Kconfig symbols that are referenced but not defined.""" | 3 | """Find Kconfig symbols that are referenced but not defined.""" |
4 | 4 | ||
@@ -128,9 +128,9 @@ def main(): | |||
128 | if opts.sim and not opts.commit and not opts.diff: | 128 | if opts.sim and not opts.commit and not opts.diff: |
129 | sims = find_sims(opts.sim, opts.ignore) | 129 | sims = find_sims(opts.sim, opts.ignore) |
130 | if sims: | 130 | if sims: |
131 | print "%s: %s" % (yel("Similar symbols"), ', '.join(sims)) | 131 | print("%s: %s" % (yel("Similar symbols"), ', '.join(sims))) |
132 | else: | 132 | else: |
133 | print "%s: no similar symbols found" % yel("Similar symbols") | 133 | print("%s: no similar symbols found" % yel("Similar symbols")) |
134 | sys.exit(0) | 134 | sys.exit(0) |
135 | 135 | ||
136 | # dictionary of (un)defined symbols | 136 | # dictionary of (un)defined symbols |
@@ -183,28 +183,28 @@ def main(): | |||
183 | 183 | ||
184 | # now print the output | 184 | # now print the output |
185 | for feature in sorted(undefined): | 185 | for feature in sorted(undefined): |
186 | print red(feature) | 186 | print(red(feature)) |
187 | 187 | ||
188 | files = sorted(undefined.get(feature)) | 188 | files = sorted(undefined.get(feature)) |
189 | print "%s: %s" % (yel("Referencing files"), ", ".join(files)) | 189 | print("%s: %s" % (yel("Referencing files"), ", ".join(files))) |
190 | 190 | ||
191 | sims = find_sims(feature, opts.ignore, defined) | 191 | sims = find_sims(feature, opts.ignore, defined) |
192 | sims_out = yel("Similar symbols") | 192 | sims_out = yel("Similar symbols") |
193 | if sims: | 193 | if sims: |
194 | print "%s: %s" % (sims_out, ', '.join(sims)) | 194 | print("%s: %s" % (sims_out, ', '.join(sims))) |
195 | else: | 195 | else: |
196 | print "%s: %s" % (sims_out, "no similar symbols found") | 196 | print("%s: %s" % (sims_out, "no similar symbols found")) |
197 | 197 | ||
198 | if opts.find: | 198 | if opts.find: |
199 | print "%s:" % yel("Commits changing symbol") | 199 | print("%s:" % yel("Commits changing symbol")) |
200 | commits = find_commits(feature, opts.diff) | 200 | commits = find_commits(feature, opts.diff) |
201 | if commits: | 201 | if commits: |
202 | for commit in commits: | 202 | for commit in commits: |
203 | commit = commit.split(" ", 1) | 203 | commit = commit.split(" ", 1) |
204 | print "\t- %s (\"%s\")" % (yel(commit[0]), commit[1]) | 204 | print("\t- %s (\"%s\")" % (yel(commit[0]), commit[1])) |
205 | else: | 205 | else: |
206 | print "\t- no commit found" | 206 | print("\t- no commit found") |
207 | print # new line | 207 | print() # new line |
208 | 208 | ||
209 | 209 | ||
210 | def yel(string): | 210 | def yel(string): |
@@ -225,7 +225,8 @@ def execute(cmd): | |||
225 | """Execute %cmd and return stdout. Exit in case of error.""" | 225 | """Execute %cmd and return stdout. Exit in case of error.""" |
226 | try: | 226 | try: |
227 | cmdlist = cmd.split(" ") | 227 | cmdlist = cmd.split(" ") |
228 | stdout = subprocess.check_output(cmdlist, stderr=STDOUT, shell=False) | 228 | stdout = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT, shell=False) |
229 | stdout = stdout.decode(errors='replace') | ||
229 | except subprocess.CalledProcessError as fail: | 230 | except subprocess.CalledProcessError as fail: |
230 | exit("Failed to execute %s\n%s" % (cmd, fail)) | 231 | exit("Failed to execute %s\n%s" % (cmd, fail)) |
231 | return stdout | 232 | return stdout |
@@ -256,7 +257,7 @@ def get_head(): | |||
256 | 257 | ||
257 | def partition(lst, size): | 258 | def partition(lst, size): |
258 | """Partition list @lst into eveni-sized lists of size @size.""" | 259 | """Partition list @lst into eveni-sized lists of size @size.""" |
259 | return [lst[i::size] for i in xrange(size)] | 260 | return [lst[i::size] for i in range(size)] |
260 | 261 | ||
261 | 262 | ||
262 | def init_worker(): | 263 | def init_worker(): |
@@ -350,7 +351,7 @@ def check_symbols_helper(pool, ignore): | |||
350 | 351 | ||
351 | # inverse mapping of referenced_features to dict(feature: [files]) | 352 | # inverse mapping of referenced_features to dict(feature: [files]) |
352 | inv_map = dict() | 353 | inv_map = dict() |
353 | for _file, features in referenced_features.iteritems(): | 354 | for _file, features in referenced_features.items(): |
354 | for feature in features: | 355 | for feature in features: |
355 | inv_map[feature] = inv_map.get(feature, set()) | 356 | inv_map[feature] = inv_map.get(feature, set()) |
356 | inv_map[feature].add(_file) | 357 | inv_map[feature].add(_file) |
@@ -388,7 +389,7 @@ def parse_source_file(sfile): | |||
388 | if not os.path.exists(sfile): | 389 | if not os.path.exists(sfile): |
389 | return references | 390 | return references |
390 | 391 | ||
391 | with open(sfile, "r") as stream: | 392 | with open(sfile, "r", encoding='utf-8', errors='replace') as stream: |
392 | lines = stream.readlines() | 393 | lines = stream.readlines() |
393 | 394 | ||
394 | for line in lines: | 395 | for line in lines: |
@@ -437,7 +438,7 @@ def parse_kconfig_file(kfile): | |||
437 | if not os.path.exists(kfile): | 438 | if not os.path.exists(kfile): |
438 | return defined, references | 439 | return defined, references |
439 | 440 | ||
440 | with open(kfile, "r") as stream: | 441 | with open(kfile, "r", encoding='utf-8', errors='replace') as stream: |
441 | lines = stream.readlines() | 442 | lines = stream.readlines() |
442 | 443 | ||
443 | for i in range(len(lines)): | 444 | for i in range(len(lines)): |