History

checkkconfigsymbols.py: port to Python 3

Python 2 is slowly dying, so port the script to Python 3.

Valentin Rothberg committed 10 years ago

Commit 7c5227a1 parent f175ba11 file · +17 −16Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/checkkconfigsymbols.py+17−16
@@ -1,4 +1,4 @@
1−#!/usr/bin/env python2
1+#!/usr/bin/env python3
22
33 """Find Kconfig symbols that are referenced but not defined."""
44
@@ -128,9 +128,9 @@ def main(): · 123 unmodified lines
128128 if opts.sim and not opts.commit and not opts.diff:
129129 sims = find_sims(opts.sim, opts.ignore)
130130 if sims:
131− print "%s: %s" % (yel("Similar symbols"), ', '.join(sims))
131+ print("%s: %s" % (yel("Similar symbols"), ', '.join(sims)))
132132 else:
133− print "%s: no similar symbols found" % yel("Similar symbols")
133+ print("%s: no similar symbols found" % yel("Similar symbols"))
134134 sys.exit(0)
135135
136136 # dictionary of (un)defined symbols
@@ -183,28 +183,28 @@ def main(): · 46 unmodified lines
183183
184184 # now print the output
185185 for feature in sorted(undefined):
186− print red(feature)
186+ print(red(feature))
187187
188188 files = sorted(undefined.get(feature))
189− print "%s: %s" % (yel("Referencing files"), ", ".join(files))
189+ print("%s: %s" % (yel("Referencing files"), ", ".join(files)))
190190
191191 sims = find_sims(feature, opts.ignore, defined)
192192 sims_out = yel("Similar symbols")
193193 if sims:
194− print "%s: %s" % (sims_out, ', '.join(sims))
194+ print("%s: %s" % (sims_out, ', '.join(sims)))
195195 else:
196− print "%s: %s" % (sims_out, "no similar symbols found")
196+ print("%s: %s" % (sims_out, "no similar symbols found"))
197197
198198 if opts.find:
199− print "%s:" % yel("Commits changing symbol")
199+ print("%s:" % yel("Commits changing symbol"))
200200 commits = find_commits(feature, opts.diff)
201201 if commits:
202202 for commit in commits:
203203 commit = commit.split(" ", 1)
204− print "\t- %s (\"%s\")" % (yel(commit[0]), commit[1])
204+ print("\t- %s (\"%s\")" % (yel(commit[0]), commit[1]))
205205 else:
206− print "\t- no commit found"
207− print # new line
206+ print("\t- no commit found")
207+ print() # new line
208208
209209
210210 def yel(string):
@@ -225,7 +225,8 @@ def execute(cmd): · 14 unmodified lines
225225 """Execute %cmd and return stdout. Exit in case of error."""
226226 try:
227227 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')
229230 except subprocess.CalledProcessError as fail:
230231 exit("Failed to execute %s\n%s" % (cmd, fail))
231232 return stdout
@@ -256,7 +257,7 @@ def get_head(): · 24 unmodified lines
256257
257258 def partition(lst, size):
258259 """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)]
260261
261262
262263 def init_worker():
@@ -350,7 +351,7 @@ def check_symbols_helper(pool, ignore): · 87 unmodified lines
350351
351352 # inverse mapping of referenced_features to dict(feature: [files])
352353 inv_map = dict()
353− for _file, features in referenced_features.iteritems():
354+ for _file, features in referenced_features.items():
354355 for feature in features:
355356 inv_map[feature] = inv_map.get(feature, set())
356357 inv_map[feature].add(_file)
@@ -388,7 +389,7 @@ def parse_source_file(sfile): · 31 unmodified lines
388389 if not os.path.exists(sfile):
389390 return references
390391
391− with open(sfile, "r") as stream:
392+ with open(sfile, "r", encoding='utf-8', errors='replace') as stream:
392393 lines = stream.readlines()
393394
394395 for line in lines:
@@ -437,7 +438,7 @@ def parse_kconfig_file(kfile): · 42 unmodified lines
437438 if not os.path.exists(kfile):
438439 return defined, references
439440
440− with open(kfile, "r") as stream:
441+ with open(kfile, "r", encoding='utf-8', errors='replace') as stream:
441442 lines = stream.readlines()
442443
443444 for i in range(len(lines)):

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t