Python 2 is slowly dying, so port the script to Python 3.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -1,4 +1,4 @@ | ||
| 1 | −#!/usr/bin/env python2 | |
| 1 | +#!/usr/bin/env python3 | |
| 2 | 2 | |
| 3 | 3 | """Find Kconfig symbols that are referenced but not defined.""" |
| 4 | 4 | |
| @@ -128,9 +128,9 @@ def main(): · 123 unmodified lines | ||
| 128 | 128 | if opts.sim and not opts.commit and not opts.diff: |
| 129 | 129 | sims = find_sims(opts.sim, opts.ignore) |
| 130 | 130 | if sims: |
| 131 | − print "%s: %s" % (yel("Similar symbols"), ', '.join(sims)) | |
| 131 | + print("%s: %s" % (yel("Similar symbols"), ', '.join(sims))) | |
| 132 | 132 | else: |
| 133 | − print "%s: no similar symbols found" % yel("Similar symbols") | |
| 133 | + print("%s: no similar symbols found" % yel("Similar symbols")) | |
| 134 | 134 | sys.exit(0) |
| 135 | 135 | |
| 136 | 136 | # dictionary of (un)defined symbols |
| @@ -183,28 +183,28 @@ def main(): · 46 unmodified lines | ||
| 183 | 183 | |
| 184 | 184 | # now print the output |
| 185 | 185 | for feature in sorted(undefined): |
| 186 | − print red(feature) | |
| 186 | + print(red(feature)) | |
| 187 | 187 | |
| 188 | 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 | 191 | sims = find_sims(feature, opts.ignore, defined) |
| 192 | 192 | sims_out = yel("Similar symbols") |
| 193 | 193 | if sims: |
| 194 | − print "%s: %s" % (sims_out, ', '.join(sims)) | |
| 194 | + print("%s: %s" % (sims_out, ', '.join(sims))) | |
| 195 | 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 | 198 | if opts.find: |
| 199 | − print "%s:" % yel("Commits changing symbol") | |
| 199 | + print("%s:" % yel("Commits changing symbol")) | |
| 200 | 200 | commits = find_commits(feature, opts.diff) |
| 201 | 201 | if commits: |
| 202 | 202 | for commit in commits: |
| 203 | 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 | 205 | else: |
| 206 | − print "\t- no commit found" | |
| 207 | − print # new line | |
| 206 | + print("\t- no commit found") | |
| 207 | + print() # new line | |
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | def yel(string): |
| @@ -225,7 +225,8 @@ def execute(cmd): · 14 unmodified lines | ||
| 225 | 225 | """Execute %cmd and return stdout. Exit in case of error.""" |
| 226 | 226 | try: |
| 227 | 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 | 230 | except subprocess.CalledProcessError as fail: |
| 230 | 231 | exit("Failed to execute %s\n%s" % (cmd, fail)) |
| 231 | 232 | return stdout |
| @@ -256,7 +257,7 @@ def get_head(): · 24 unmodified lines | ||
| 256 | 257 | |
| 257 | 258 | def partition(lst, size): |
| 258 | 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 | 263 | def init_worker(): |
| @@ -350,7 +351,7 @@ def check_symbols_helper(pool, ignore): · 87 unmodified lines | ||
| 350 | 351 | |
| 351 | 352 | # inverse mapping of referenced_features to dict(feature: [files]) |
| 352 | 353 | inv_map = dict() |
| 353 | − for _file, features in referenced_features.iteritems(): | |
| 354 | + for _file, features in referenced_features.items(): | |
| 354 | 355 | for feature in features: |
| 355 | 356 | inv_map[feature] = inv_map.get(feature, set()) |
| 356 | 357 | inv_map[feature].add(_file) |
| @@ -388,7 +389,7 @@ def parse_source_file(sfile): · 31 unmodified lines | ||
| 388 | 389 | if not os.path.exists(sfile): |
| 389 | 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 | 393 | lines = stream.readlines() |
| 393 | 394 | |
| 394 | 395 | for line in lines: |
| @@ -437,7 +438,7 @@ def parse_kconfig_file(kfile): · 42 unmodified lines | ||
| 437 | 438 | if not os.path.exists(kfile): |
| 438 | 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 | 442 | lines = stream.readlines() |
| 442 | 443 | |
| 443 | 444 | for i in range(len(lines)): |