ath11k-check: port to python3

Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
This commit is contained in:
Kalle Valo 2022-02-08 17:27:23 +02:00
parent 25a662da8a
commit e471454ac6

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2015-2017 Qualcomm Atheros, Inc.
# Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
@ -25,7 +25,7 @@ import sys
import argparse
import re
import tempfile
import Queue
import queue
import threading
import string
import hashlib
@ -121,7 +121,7 @@ def run_gcc(args):
cmd = 'rm -f %s/*.o' % (DRIVER_DIR)
logger.debug('%s' % cmd)
subprocess.call(cmd, shell=True)
subprocess.call(cmd, shell=True, universal_newlines=True)
cmd = ['make', '-k', '-j', str(threads)]
@ -139,7 +139,7 @@ def run_gcc(args):
logger.debug('%s' % cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
env=env, universal_newlines=True)
(stdout, stderr) = p.communicate()
stderr = stderr.strip()
@ -151,7 +151,7 @@ def run_gcc(args):
logger.debug('FILTERED: %s' % line)
continue
print line.strip()
print(line.strip())
return p.returncode
@ -160,7 +160,8 @@ def run_sparse(args):
cmd = ['make', '-k', '-j',
str(threads), DRIVER_DIR, 'C=2', 'CF="-D__CHECK_ENDIAN__"']
logger.debug('%s' % cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
(stdout, stderr) = p.communicate()
stderr = stderr.strip()
@ -182,7 +183,7 @@ def run_sparse(args):
break
if not drop:
print line.strip()
print(line.strip())
return p.returncode
@ -248,13 +249,13 @@ def run_checkpatch_cmd(args, q, tag_map):
while True:
try:
f = q.get_nowait()
except Queue.Empty:
except queue.Empty:
# no more files to check
break
cmd = checkpatch_cmd + [f]
p = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
(stdoutdata, stderrdata) = p.communicate()
if stdoutdata is None:
@ -270,7 +271,7 @@ def run_checkpatch_cmd(args, q, tag_map):
continue
logger.debug(w)
print '%s:%s: %s' % (w.path, w.lineno, w.msg)
print('%s:%s: %s' % (w.path, w.lineno, w.msg))
q.task_done()
@ -278,7 +279,7 @@ def run_checkpatch_cmd(args, q, tag_map):
def run_checkpatch(args):
# get all files which need to be checked
cmd = 'git ls-tree HEAD %s | cut -f 2' % (DRIVER_DIR)
output = subprocess.check_output(cmd, shell=True)
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
driver_files = output.splitlines()
# drop files we need to ignore
@ -299,7 +300,7 @@ def run_checkpatch(args):
cmd = 'gtags -f %s' % (tmpfilename)
logger.debug('%s' % (cmd))
output = subprocess.check_output(cmd, shell=True)
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
os.remove(tmpfilename)
@ -313,7 +314,7 @@ def run_checkpatch(args):
continue
cmd = 'global -f %s' % (f)
output = subprocess.check_output(cmd, shell=True)
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
lines = output.splitlines()
for l in lines:
columns = l.split()
@ -325,7 +326,7 @@ def run_checkpatch(args):
tag_map[f].append((line, tagname))
q = Queue.Queue()
q = queue.Queue()
for f in driver_files:
q.put(f)
@ -351,42 +352,45 @@ def show_version(args):
run = subprocess.check_output
f = open(sys.argv[0], 'r')
f = open(sys.argv[0], 'rb')
ath11kcheck_md5sum = hashlib.md5(f.read()).hexdigest()
f.close()
try:
gcc_version = run(['gcc', '--version']).splitlines()[0]
gcc_version = run(['gcc', '--version'],
universal_newlines=True).splitlines()[0]
except:
pass
try:
sparse_version = run(['sparse', '--version']).splitlines()[0]
sparse_version = run(['sparse', '--version'],
universal_newlines=True).splitlines()[0]
except:
pass
try:
checkpatch_version = run(
['checkpatch.pl', '--version']).splitlines()[1]
checkpatch_version = run(['checkpatch.pl', '--version'],
universal_newlines=True).splitlines()[1]
path = distutils.spawn.find_executable(
'checkpatch.pl', os.environ['PATH'])
f = open(path, 'r')
f = open(path, 'rb')
checkpatch_md5sum = hashlib.md5(f.read()).hexdigest()
f.close()
except:
pass
try:
gtags_version = run(['gtags', '--version']).splitlines()[0]
gtags_version = run(['gtags', '--version'],
universal_newlines=True).splitlines()[0]
except:
pass
print 'ath11k-check (md5sum %s)' % (ath11kcheck_md5sum)
print
print 'gcc:\t\t%s' % (gcc_version)
print 'sparse:\t\t%s' % (sparse_version)
print 'checkpatch.pl:\t%s (md5sum %s)' % (checkpatch_version, checkpatch_md5sum)
print 'gtags:\t\t%s' % (gtags_version)
print('ath11k-check (md5sum %s)' % (ath11kcheck_md5sum))
print()
print('gcc:\t\t%s' % (gcc_version))
print('sparse:\t\t%s' % (sparse_version))
print('checkpatch.pl:\t%s (md5sum %s)' % (checkpatch_version, checkpatch_md5sum))
print('gtags:\t\t%s' % (gtags_version))
sys.exit(0)
@ -477,8 +481,9 @@ $CHECKPATCH_CMDLINE
checkpatch = True
try:
cores = subprocess.check_output(['nproc'])
except OSError, subprocess.CalledProcessError:
cores = subprocess.check_output(['nproc'], universal_newlines=True)
except OSError as xxx_todo_changeme:
subprocess.CalledProcessError = xxx_todo_changeme
cores = '4'
logger.warning('Failed to run nproc, assuming %s cores' % (cores))