mirror of
https://github.com/qca/qca-swiss-army-knife.git
synced 2026-01-27 17:07:18 +01:00
Fix Python 3 syntax errors in ath10k tools
Since Python 2 is soon to be deprecated it would be nice if the tool works with a python3 interpreter (default on many distros). Previous commits addressing these issues did not solve all issues (not all print statements were converted etc.). Signed-off-by: Erik Stromdahl <erik.stromdahl@gmail.com>
This commit is contained in:
parent
8c813ad8b8
commit
60bec5a5b9
4 changed files with 62 additions and 59 deletions
|
|
@ -620,8 +620,8 @@ def cmd_add_mbox(args):
|
|||
name = filename.rstrip(BIN_SUFFIX)
|
||||
board_files[name] = part.get_payload(decode=True)
|
||||
|
||||
print 'Found mail "%s" with %d board files' % (msg['Subject'],
|
||||
len(board_files))
|
||||
print('Found mail "%s" with %d board files' % (msg['Subject'],
|
||||
len(board_files)))
|
||||
|
||||
# copy the original file for diff
|
||||
(temp_fd, temp_pathname) = tempfile.mkstemp()
|
||||
|
|
@ -650,9 +650,9 @@ def cmd_add_mbox(args):
|
|||
|
||||
os.remove(temp_pathname)
|
||||
|
||||
print '----------------------------------------------'
|
||||
print applied_msg
|
||||
print '----------------------------------------------'
|
||||
print('----------------------------------------------')
|
||||
print(applied_msg)
|
||||
print('----------------------------------------------')
|
||||
|
||||
xclip(applied_msg)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ import sys
|
|||
import argparse
|
||||
import re
|
||||
import tempfile
|
||||
import Queue
|
||||
try:
|
||||
import queue as Queue
|
||||
except ImportError:
|
||||
import Queue
|
||||
import threading
|
||||
import string
|
||||
import hashlib
|
||||
|
|
@ -149,7 +152,7 @@ def run_gcc(args):
|
|||
logger.debug('FILTERED: %s' % line)
|
||||
continue
|
||||
|
||||
print line.strip()
|
||||
print(line.strip())
|
||||
|
||||
return p.returncode
|
||||
|
||||
|
|
@ -170,7 +173,7 @@ def run_sparse(args):
|
|||
logger.debug('FILTERED: %s' % line)
|
||||
continue
|
||||
|
||||
print line.strip()
|
||||
print(line.strip())
|
||||
|
||||
return p.returncode
|
||||
|
||||
|
|
@ -258,7 +261,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()
|
||||
|
||||
|
|
@ -365,12 +368,12 @@ def show_version(args):
|
|||
except:
|
||||
pass
|
||||
|
||||
print 'ath10k-check (md5sum %s)' % (ath10kcheck_md5sum)
|
||||
print('ath10k-check (md5sum %s)' % (ath10kcheck_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('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)
|
||||
|
||||
|
|
@ -462,7 +465,7 @@ $CHECKPATCH_CMDLINE
|
|||
|
||||
try:
|
||||
cores = subprocess.check_output(['nproc'])
|
||||
except OSError, subprocess.CalledProcessError:
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
cores = '4'
|
||||
logger.warning('Failed to run nproc, assuming %s cores' % (cores))
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class FirmwareBranch():
|
|||
|
||||
self.priority = int(buf)
|
||||
except Exception as e:
|
||||
print 'Failed to read %s: %s' % (priority_path, e)
|
||||
print('Failed to read %s: %s' % (priority_path, e))
|
||||
|
||||
|
||||
class BoardFile():
|
||||
|
|
@ -400,7 +400,7 @@ def get_board_crc32(path):
|
|||
|
||||
# print indent
|
||||
def pi(level, msg):
|
||||
print '%s%s' % (level * '\t', msg)
|
||||
print('%s%s' % (level * '\t', msg))
|
||||
|
||||
|
||||
def whence_update(linux_firmware, firmware_path, version):
|
||||
|
|
@ -416,7 +416,7 @@ def whence_update(linux_firmware, firmware_path, version):
|
|||
(buf, sub_count) = re.subn(pattern, replace, buf, flags=re.MULTILINE)
|
||||
|
||||
if sub_count != 1:
|
||||
print 'Failed to update %s to WHENCE: %d' % (firmware_path, sub_count)
|
||||
print('Failed to update %s to WHENCE: %d' % (firmware_path, sub_count))
|
||||
return
|
||||
|
||||
f = open(os.path.join(linux_firmware, WHENCE_FILE), 'w')
|
||||
|
|
@ -443,7 +443,7 @@ def whence_add(linux_firmware, firmware_path, version, license_path=None):
|
|||
(buf, sub_count) = re.subn(pattern, replace, buf, flags=re.MULTILINE | re.DOTALL)
|
||||
|
||||
if sub_count != 1:
|
||||
print 'Failed to add %s to WHENCE: %d' % (firmware_path, sub_count)
|
||||
print('Failed to add %s to WHENCE: %d' % (firmware_path, sub_count))
|
||||
return
|
||||
|
||||
f = open(os.path.join(linux_firmware, WHENCE_FILE), 'w')
|
||||
|
|
@ -517,11 +517,11 @@ def cmd_list_lib_dir(args):
|
|||
ath10k_dir = os.path.join(fw_dir, 'ath10k')
|
||||
|
||||
if not os.path.exists(ath10k_dir):
|
||||
print 'directory %s does not exist, aborting' % (ath10k_dir)
|
||||
print('directory %s does not exist, aborting' % (ath10k_dir))
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.isdir(ath10k_dir):
|
||||
print '%s is not a directory, aborting' % (ath10k_dir)
|
||||
print('%s is not a directory, aborting' % (ath10k_dir))
|
||||
sys.exit(1)
|
||||
|
||||
# sort the results based on dirpath
|
||||
|
|
@ -568,7 +568,7 @@ def cmd_get_latest_in_branch(args):
|
|||
hw_name = '%s %s' % (args_hw, args_hwver)
|
||||
|
||||
if hw_name not in hws:
|
||||
print 'Did not find hardware: %s' % (hw_name)
|
||||
print('Did not find hardware: %s' % (hw_name))
|
||||
sys.exit(1)
|
||||
|
||||
hw = hws[hw_name]
|
||||
|
|
@ -581,14 +581,14 @@ def cmd_get_latest_in_branch(args):
|
|||
break
|
||||
|
||||
if fw_branch is None:
|
||||
print 'Did not find firmware branch: %s' % (args_fwbranch)
|
||||
print('Did not find firmware branch: %s' % (args_fwbranch))
|
||||
sys.exit(1)
|
||||
|
||||
if len(fw_branch.firmwares) == 0:
|
||||
# no firmware images in this branch, just use return value 0 with no output
|
||||
sys.exit(0)
|
||||
|
||||
print sorted(fw_branch.firmwares)[-1].path
|
||||
print(sorted(fw_branch.firmwares)[-1].path)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
@ -609,7 +609,7 @@ def cmd_get_latest_in_hw(args):
|
|||
hw_name = '%s %s' % (args_hw, args_hwver)
|
||||
|
||||
if hw_name not in hws:
|
||||
print 'Did not find hardware: %s' % (hw_name)
|
||||
print('Did not find hardware: %s' % (hw_name))
|
||||
sys.exit(1)
|
||||
|
||||
hw = hws[hw_name]
|
||||
|
|
@ -620,7 +620,7 @@ def cmd_get_latest_in_hw(args):
|
|||
# no firmware images in this branch, just use return value 0 with no output
|
||||
sys.exit(0)
|
||||
|
||||
print sorted(fw_branch.firmwares)[-1].path
|
||||
print(sorted(fw_branch.firmwares)[-1].path)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ class Ath10kFirmwareContainer(object):
|
|||
elif is_int(s):
|
||||
version = s
|
||||
else:
|
||||
print 'Error: Invalid HTT OP version: %s' % s
|
||||
print('Error: Invalid HTT OP version: %s' % s)
|
||||
return 1
|
||||
|
||||
self.htt_op_version = version
|
||||
|
|
@ -353,7 +353,7 @@ class Ath10kFirmwareContainer(object):
|
|||
elif is_int(s):
|
||||
version = s
|
||||
else:
|
||||
print 'Error: Invalid WMI OP version: %s' % s
|
||||
print('Error: Invalid WMI OP version: %s' % s)
|
||||
return 1
|
||||
|
||||
self.wmi_op_version = version
|
||||
|
|
@ -376,7 +376,7 @@ class Ath10kFirmwareContainer(object):
|
|||
enabled = []
|
||||
for capa in self.features:
|
||||
if capa not in feature_map:
|
||||
print "Error: '%s' not found from the feature map" % capa
|
||||
print("Error: '%s' not found from the feature map" % capa)
|
||||
return 1
|
||||
|
||||
enabled.append(feature_map[capa])
|
||||
|
|
@ -434,7 +434,7 @@ class Ath10kFirmwareContainer(object):
|
|||
self.fw_version = fw_version
|
||||
# reserve one byte for null
|
||||
if len(self.fw_version) > ETHTOOL_FWVERS_LEN - 1:
|
||||
print 'Firmware version string too long: %d' % (len(self.fw_version))
|
||||
print('Firmware version string too long: %d' % (len(self.fw_version)))
|
||||
return 1
|
||||
|
||||
def get_fw_version(self):
|
||||
|
|
@ -500,7 +500,7 @@ class Ath10kFirmwareContainer(object):
|
|||
elif e == ATH10K_FW_IE_FW_CODE_SWAP_IMAGE:
|
||||
self.fw_code_swap_image = c.elements[e]
|
||||
else:
|
||||
print "Unknown IE: ", e
|
||||
print("Unknown IE: ", e)
|
||||
|
||||
def save(self, filename):
|
||||
self.container = FirmwareContainer(ATH10K_SIGNATURE)
|
||||
|
|
@ -585,7 +585,7 @@ def write_file(filename, buf):
|
|||
def info(options, args):
|
||||
|
||||
if len(args) != 1:
|
||||
print 'Filename missing'
|
||||
print('Filename missing')
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
|
|
@ -593,13 +593,13 @@ def info(options, args):
|
|||
c = Ath10kFirmwareContainer()
|
||||
c.load(filename)
|
||||
|
||||
print c.get_summary()
|
||||
print(c.get_summary())
|
||||
|
||||
|
||||
def dump(options, args):
|
||||
|
||||
if len(args) != 1:
|
||||
print 'Filename missing'
|
||||
print('Filename missing')
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
|
|
@ -607,42 +607,42 @@ def dump(options, args):
|
|||
c = Ath10kFirmwareContainer()
|
||||
c.load(filename)
|
||||
|
||||
print "ath10k-fwencoder --create \\"
|
||||
print("ath10k-fwencoder --create \\")
|
||||
|
||||
if c.get_fw_version():
|
||||
print "--firmware-version=%s \\" % c.get_fw_version()
|
||||
print("--firmware-version=%s \\" % c.get_fw_version())
|
||||
|
||||
if c.get_timestamp() and options.show_timestamp:
|
||||
print "--timestamp=%u \\" % c.get_timestamp()
|
||||
print("--timestamp=%u \\" % c.get_timestamp())
|
||||
|
||||
if c.get_features():
|
||||
print "--features=%s \\" % c.get_features()
|
||||
print("--features=%s \\" % c.get_features())
|
||||
|
||||
if c.get_fw_image():
|
||||
name = "athwlan.bin"
|
||||
print "--firmware=%s \\" % name
|
||||
print("--firmware=%s \\" % name)
|
||||
|
||||
if c.get_otp_image():
|
||||
name = "otp.bin"
|
||||
print "--otp=%s \\" % name
|
||||
print("--otp=%s \\" % name)
|
||||
|
||||
if c.get_wmi_op_version():
|
||||
print '--set-wmi-op-version=%s \\' % c.get_wmi_op_version()
|
||||
print('--set-wmi-op-version=%s \\' % c.get_wmi_op_version())
|
||||
|
||||
if c.get_htt_op_version():
|
||||
print '--set-htt-op-version=%s \\' % (c.get_htt_op_version())
|
||||
print('--set-htt-op-version=%s \\' % (c.get_htt_op_version()))
|
||||
|
||||
if c.get_fw_code_swap_image():
|
||||
name = "athwlan.codeswap.bin"
|
||||
print "--firmware-codeswap=%s \\" % name
|
||||
print("--firmware-codeswap=%s \\" % name)
|
||||
|
||||
print
|
||||
print()
|
||||
|
||||
|
||||
def extract(options, args):
|
||||
|
||||
if len(args) != 1:
|
||||
print 'Filename missing'
|
||||
print('Filename missing')
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
|
|
@ -653,24 +653,24 @@ def extract(options, args):
|
|||
if c.get_fw_image():
|
||||
name = "athwlan.bin"
|
||||
write_file(name, c.get_fw_image())
|
||||
print '%s extracted: %d B' % (name, len(c.get_fw_image()))
|
||||
print('%s extracted: %d B' % (name, len(c.get_fw_image())))
|
||||
|
||||
if c.get_otp_image():
|
||||
name = "otp.bin"
|
||||
write_file(name, c.get_otp_image())
|
||||
print '%s extracted: %d B' % (name, len(c.get_otp_image()))
|
||||
print('%s extracted: %d B' % (name, len(c.get_otp_image())))
|
||||
|
||||
if c.get_fw_code_swap_image():
|
||||
name = "athwlan.codeswap.bin"
|
||||
write_file(name, c.get_fw_code_swap_image())
|
||||
print '%s extracted: %d B' % (name, len(c.get_fw_code_swap_image()))
|
||||
print('%s extracted: %d B' % (name, len(c.get_fw_code_swap_image())))
|
||||
|
||||
print
|
||||
print()
|
||||
|
||||
|
||||
def modify(options, args):
|
||||
if len(args) != 1:
|
||||
print 'Filename missing'
|
||||
print('Filename missing')
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
|
|
@ -710,7 +710,7 @@ def modify(options, args):
|
|||
|
||||
file_len = c.save(filename)
|
||||
|
||||
print '%s modified: %d B' % (filename, file_len)
|
||||
print('%s modified: %d B' % (filename, file_len))
|
||||
|
||||
|
||||
def create(options):
|
||||
|
|
@ -752,25 +752,25 @@ def create(options):
|
|||
|
||||
file_len = c.save(output)
|
||||
|
||||
print '%s created: %d B' % (output, file_len)
|
||||
print('%s created: %d B' % (output, file_len))
|
||||
|
||||
|
||||
def cmd_crc32(options, args):
|
||||
if len(args) != 1:
|
||||
print 'Filename missing'
|
||||
print('Filename missing')
|
||||
return 1
|
||||
|
||||
filename = args[0]
|
||||
|
||||
f = open(filename, 'r')
|
||||
buf = f.read()
|
||||
print '%08x' % (_crc32(buf))
|
||||
print('%08x' % (_crc32(buf)))
|
||||
f.close()
|
||||
|
||||
|
||||
def cmd_diff(options, args):
|
||||
if len(args) != 2:
|
||||
print 'Usage: ath10k-fwencoder --diff FILE FILE'
|
||||
print('Usage: ath10k-fwencoder --diff FILE FILE')
|
||||
return 1
|
||||
|
||||
filename1 = args[0]
|
||||
|
|
@ -804,7 +804,7 @@ def cmd_diff(options, args):
|
|||
logger.error('Failed to run wdiff: %s' % (e))
|
||||
return 1
|
||||
|
||||
print output
|
||||
print(output)
|
||||
|
||||
os.close(temp1_fd)
|
||||
os.close(temp2_fd)
|
||||
|
|
@ -896,10 +896,10 @@ def main():
|
|||
try:
|
||||
return create(options)
|
||||
except FWEncoderError as e:
|
||||
print 'Create failed: %s' % e
|
||||
print('Create failed: %s' % e)
|
||||
sys.exit(2)
|
||||
except Exception as e:
|
||||
print 'Create failed: %s' % e
|
||||
print('Create failed: %s' % e)
|
||||
traceback.print_exc()
|
||||
sys.exit(3)
|
||||
elif options.dump:
|
||||
|
|
@ -915,7 +915,7 @@ def main():
|
|||
elif options.diff:
|
||||
return cmd_diff(options, args)
|
||||
else:
|
||||
print 'Action command missing'
|
||||
print('Action command missing')
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue