mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-20 21:51:05 +00:00
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>
This commit is contained in:
parent
f175ba174e
commit
7c5227af25
1 changed files with 17 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""Find Kconfig symbols that are referenced but not defined."""
|
"""Find Kconfig symbols that are referenced but not defined."""
|
||||||
|
|
||||||
|
@ -128,9 +128,9 @@ def main():
|
||||||
if opts.sim and not opts.commit and not opts.diff:
|
if opts.sim and not opts.commit and not opts.diff:
|
||||||
sims = find_sims(opts.sim, opts.ignore)
|
sims = find_sims(opts.sim, opts.ignore)
|
||||||
if sims:
|
if sims:
|
||||||
print "%s: %s" % (yel("Similar symbols"), ', '.join(sims))
|
print("%s: %s" % (yel("Similar symbols"), ', '.join(sims)))
|
||||||
else:
|
else:
|
||||||
print "%s: no similar symbols found" % yel("Similar symbols")
|
print("%s: no similar symbols found" % yel("Similar symbols"))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# dictionary of (un)defined symbols
|
# dictionary of (un)defined symbols
|
||||||
|
@ -183,28 +183,28 @@ def main():
|
||||||
|
|
||||||
# now print the output
|
# now print the output
|
||||||
for feature in sorted(undefined):
|
for feature in sorted(undefined):
|
||||||
print red(feature)
|
print(red(feature))
|
||||||
|
|
||||||
files = sorted(undefined.get(feature))
|
files = sorted(undefined.get(feature))
|
||||||
print "%s: %s" % (yel("Referencing files"), ", ".join(files))
|
print("%s: %s" % (yel("Referencing files"), ", ".join(files)))
|
||||||
|
|
||||||
sims = find_sims(feature, opts.ignore, defined)
|
sims = find_sims(feature, opts.ignore, defined)
|
||||||
sims_out = yel("Similar symbols")
|
sims_out = yel("Similar symbols")
|
||||||
if sims:
|
if sims:
|
||||||
print "%s: %s" % (sims_out, ', '.join(sims))
|
print("%s: %s" % (sims_out, ', '.join(sims)))
|
||||||
else:
|
else:
|
||||||
print "%s: %s" % (sims_out, "no similar symbols found")
|
print("%s: %s" % (sims_out, "no similar symbols found"))
|
||||||
|
|
||||||
if opts.find:
|
if opts.find:
|
||||||
print "%s:" % yel("Commits changing symbol")
|
print("%s:" % yel("Commits changing symbol"))
|
||||||
commits = find_commits(feature, opts.diff)
|
commits = find_commits(feature, opts.diff)
|
||||||
if commits:
|
if commits:
|
||||||
for commit in commits:
|
for commit in commits:
|
||||||
commit = commit.split(" ", 1)
|
commit = commit.split(" ", 1)
|
||||||
print "\t- %s (\"%s\")" % (yel(commit[0]), commit[1])
|
print("\t- %s (\"%s\")" % (yel(commit[0]), commit[1]))
|
||||||
else:
|
else:
|
||||||
print "\t- no commit found"
|
print("\t- no commit found")
|
||||||
print # new line
|
print() # new line
|
||||||
|
|
||||||
|
|
||||||
def yel(string):
|
def yel(string):
|
||||||
|
@ -225,7 +225,8 @@ def execute(cmd):
|
||||||
"""Execute %cmd and return stdout. Exit in case of error."""
|
"""Execute %cmd and return stdout. Exit in case of error."""
|
||||||
try:
|
try:
|
||||||
cmdlist = cmd.split(" ")
|
cmdlist = cmd.split(" ")
|
||||||
stdout = subprocess.check_output(cmdlist, stderr=STDOUT, shell=False)
|
stdout = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT, shell=False)
|
||||||
|
stdout = stdout.decode(errors='replace')
|
||||||
except subprocess.CalledProcessError as fail:
|
except subprocess.CalledProcessError as fail:
|
||||||
exit("Failed to execute %s\n%s" % (cmd, fail))
|
exit("Failed to execute %s\n%s" % (cmd, fail))
|
||||||
return stdout
|
return stdout
|
||||||
|
@ -256,7 +257,7 @@ def get_head():
|
||||||
|
|
||||||
def partition(lst, size):
|
def partition(lst, size):
|
||||||
"""Partition list @lst into eveni-sized lists of size @size."""
|
"""Partition list @lst into eveni-sized lists of size @size."""
|
||||||
return [lst[i::size] for i in xrange(size)]
|
return [lst[i::size] for i in range(size)]
|
||||||
|
|
||||||
|
|
||||||
def init_worker():
|
def init_worker():
|
||||||
|
@ -350,7 +351,7 @@ def check_symbols_helper(pool, ignore):
|
||||||
|
|
||||||
# inverse mapping of referenced_features to dict(feature: [files])
|
# inverse mapping of referenced_features to dict(feature: [files])
|
||||||
inv_map = dict()
|
inv_map = dict()
|
||||||
for _file, features in referenced_features.iteritems():
|
for _file, features in referenced_features.items():
|
||||||
for feature in features:
|
for feature in features:
|
||||||
inv_map[feature] = inv_map.get(feature, set())
|
inv_map[feature] = inv_map.get(feature, set())
|
||||||
inv_map[feature].add(_file)
|
inv_map[feature].add(_file)
|
||||||
|
@ -388,7 +389,7 @@ def parse_source_file(sfile):
|
||||||
if not os.path.exists(sfile):
|
if not os.path.exists(sfile):
|
||||||
return references
|
return references
|
||||||
|
|
||||||
with open(sfile, "r") as stream:
|
with open(sfile, "r", encoding='utf-8', errors='replace') as stream:
|
||||||
lines = stream.readlines()
|
lines = stream.readlines()
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
@ -437,7 +438,7 @@ def parse_kconfig_file(kfile):
|
||||||
if not os.path.exists(kfile):
|
if not os.path.exists(kfile):
|
||||||
return defined, references
|
return defined, references
|
||||||
|
|
||||||
with open(kfile, "r") as stream:
|
with open(kfile, "r", encoding='utf-8', errors='replace') as stream:
|
||||||
lines = stream.readlines()
|
lines = stream.readlines()
|
||||||
|
|
||||||
for i in range(len(lines)):
|
for i in range(len(lines)):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue