Enforce E501: Limit the line length to 79 for files in pmb/parse - part 2 (MR 2020)

Made changes to limit the line length in following files,
 - pmb/parse/bootimg.py
 - pmb/parse/depends.py
 - pmb/parse/kconfig.py
 - test/test_parse_depends.py

Added the above files in E501 flake8 command list.
Substitute f-string for string concatenation.
This commit is contained in:
Shubham Naik 2021-01-31 23:51:56 +05:30 committed by Oliver Smith
parent d1fadba5b4
commit 684cb3e1fb
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
5 changed files with 63 additions and 47 deletions

View File

@ -25,9 +25,9 @@ def has_mtk_header(path, supported_label):
# this, deviceinfo would need to store the label and # this, deviceinfo would need to store the label and
# postmarketos-mkinitfs would need to use that label. # postmarketos-mkinitfs would need to use that label.
if label != supported_label: if label != supported_label:
raise RuntimeError(f"Only '{supported_label}' is supported as label," raise RuntimeError(f"Only '{supported_label}' is supported as"
f" but your device has '{label}'. Please create" f" label, but your device has '{label}'. Please"
f" an issue and attach your boot.img:" f" create an issue and attach your boot.img:"
f" https://postmarketos.org/issues") f" https://postmarketos.org/issues")
return True return True
@ -36,12 +36,12 @@ def bootimg(args, path):
if not os.path.exists(path): if not os.path.exists(path):
raise RuntimeError("Could not find file '" + path + "'") raise RuntimeError("Could not find file '" + path + "'")
logging.info("NOTE: You will be prompted for your sudo password, so we can set" logging.info("NOTE: You will be prompted for your sudo password, so we can"
" up a chroot to extract and analyze your boot.img file") " set up a chroot to extract and analyze your boot.img file")
pmb.chroot.apk.install(args, ["file", "unpackbootimg"]) pmb.chroot.apk.install(args, ["file", "unpackbootimg"])
temp_path = pmb.chroot.other.tempfolder(args, "/tmp/bootimg_parser") temp_path = pmb.chroot.other.tempfolder(args, "/tmp/bootimg_parser")
bootimg_path = args.work + "/chroot_native" + temp_path + "/boot.img" bootimg_path = f"{args.work}/chroot_native{temp_path}/boot.img"
# Copy the boot.img into the chroot temporary folder # Copy the boot.img into the chroot temporary folder
pmb.helpers.run.root(args, ["cp", path, bootimg_path]) pmb.helpers.run.root(args, ["cp", path, bootimg_path])
@ -69,32 +69,40 @@ def bootimg(args, path):
file_output + ")") file_output + ")")
# Extract all the files # Extract all the files
pmb.chroot.user(args, ["unpackbootimg", "-i", "boot.img"], working_dir=temp_path) pmb.chroot.user(args, ["unpackbootimg", "-i", "boot.img"],
working_dir=temp_path)
output = {} output = {}
# Get base, offsets, pagesize, cmdline and qcdt info # Get base, offsets, pagesize, cmdline and qcdt info
with open(bootimg_path + "-base", 'r') as f: with open(bootimg_path + "-base", 'r') as f:
output["base"] = ("0x%08x" % int(f.read().replace('\n', ''), 16)) output["base"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-kernel_offset", 'r') as f: with open(bootimg_path + "-kernel_offset", 'r') as f:
output["kernel_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16)) output["kernel_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-ramdisk_offset", 'r') as f: with open(bootimg_path + "-ramdisk_offset", 'r') as f:
output["ramdisk_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16)) output["ramdisk_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-second_offset", 'r') as f: with open(bootimg_path + "-second_offset", 'r') as f:
output["second_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16)) output["second_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-tags_offset", 'r') as f: with open(bootimg_path + "-tags_offset", 'r') as f:
output["tags_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16)) output["tags_offset"] = ("0x%08x"
% int(f.read().replace('\n', ''), 16))
with open(bootimg_path + "-pagesize", 'r') as f: with open(bootimg_path + "-pagesize", 'r') as f:
output["pagesize"] = f.read().replace('\n', '') output["pagesize"] = f.read().replace('\n', '')
with open(bootimg_path + "-cmdline", 'r') as f: with open(bootimg_path + "-cmdline", 'r') as f:
output["cmdline"] = f.read().replace('\n', '') output["cmdline"] = f.read().replace('\n', '')
output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dt") and output["qcdt"] = ("true" if os.path.isfile(f"{bootimg_path}-dt") and
os.path.getsize(bootimg_path + "-dt") > 0 else "false") os.path.getsize(f"{bootimg_path}-dt") > 0 else "false")
output["mtk_mkimage"] = ("true" if has_mtk_header(bootimg_path + "-zImage", "KERNEL") else "false") output["mtk_mkimage"] = ("true" if has_mtk_header(f"{bootimg_path}-zImage",
output["dtb_second"] = ("true" if is_dtb(bootimg_path + "-second") else "false") "KERNEL") else "false")
output["dtb_second"] = ("true" if is_dtb(f"{bootimg_path}-second")
else "false")
# Mediatek: Check that the ramdisk also has a known-good label # Mediatek: Check that the ramdisk also has a known-good label
# We don't care about the return value, just whether it throws an exception or not. # We don't care about the return value, just whether it throws an exception
has_mtk_header(bootimg_path + "-ramdisk.gz", "ROOTFS") # or not.
has_mtk_header(f"{bootimg_path}-ramdisk.gz", "ROOTFS")
# Cleanup # Cleanup
pmb.chroot.root(args, ["rm", "-r", temp_path]) pmb.chroot.root(args, ["rm", "-r", temp_path])

View File

@ -24,8 +24,8 @@ def package_from_aports(args, pkgname_depend):
version = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"] version = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
# Return the dict # Return the dict
logging.verbose(pkgname_depend + ": provided by: " + pkgname + "-" + logging.verbose(
version + " in " + aport) f"{pkgname_depend}: provided by: {pkgname}-{version} in {aport}")
return {"pkgname": pkgname, return {"pkgname": pkgname,
"depends": apkbuild["depends"], "depends": apkbuild["depends"],
"version": version} "version": version}
@ -46,35 +46,35 @@ def package_provider(args, pkgname, pkgnames_install, suffix="native"):
return None return None
# 1. Only one provider # 1. Only one provider
logging.verbose(pkgname + ": provided by: " + ", ".join(providers)) logging.verbose(f"{pkgname}: provided by: {', '.join(providers)}")
if len(providers) == 1: if len(providers) == 1:
return list(providers.values())[0] return list(providers.values())[0]
# 2. Provider with the same package name # 2. Provider with the same package name
if pkgname in providers: if pkgname in providers:
logging.verbose(pkgname + ": choosing package of the same name as" logging.verbose(f"{pkgname}: choosing package of the same name as "
"provider") "provider")
return providers[pkgname] return providers[pkgname]
# 3. Pick a package that will be installed anyway # 3. Pick a package that will be installed anyway
for provider_pkgname, provider in providers.items(): for provider_pkgname, provider in providers.items():
if provider_pkgname in pkgnames_install: if provider_pkgname in pkgnames_install:
logging.verbose(pkgname + ": choosing provider '" + logging.verbose(f"{pkgname}: choosing provider '{provider_pkgname}"
provider_pkgname + "', because it will be" "', because it will be installed anyway")
" installed anyway")
return provider return provider
# 4. Pick a package that is already installed # 4. Pick a package that is already installed
installed = pmb.chroot.apk.installed(args, suffix) installed = pmb.chroot.apk.installed(args, suffix)
for provider_pkgname, provider in providers.items(): for provider_pkgname, provider in providers.items():
if provider_pkgname in installed: if provider_pkgname in installed:
logging.verbose(pkgname + ": choosing provider '" + logging.verbose(f"{pkgname}: choosing provider '{provider_pkgname}"
provider_pkgname + "', because it is installed in" f"', because it is installed in the '{suffix}' "
" the '" + suffix + "' chroot already") "chroot already")
return provider return provider
# 5. Pick the provider(s) with the highest priority # 5. Pick the provider(s) with the highest priority
providers = pmb.parse.apkindex.provider_highest_priority(providers, pkgname) providers = pmb.parse.apkindex.provider_highest_priority(
providers, pkgname)
if len(providers) == 1: if len(providers) == 1:
return list(providers.values())[0] return list(providers.values())[0]
@ -118,8 +118,8 @@ def recurse(args, pkgnames, suffix="native"):
:returns: list of pkgnames: consists of the initial pkgnames plus all :returns: list of pkgnames: consists of the initial pkgnames plus all
depends depends
""" """
logging.debug("(" + suffix + ") calculate depends of " + logging.debug(f"({suffix}) calculate depends of {', '.join(pkgnames)} "
", ".join(pkgnames) + " (pmbootstrap -v for details)") "(pmbootstrap -v for details)")
# Iterate over todo-list until is is empty # Iterate over todo-list until is is empty
todo = list(pkgnames) todo = list(pkgnames)
@ -138,17 +138,17 @@ def recurse(args, pkgnames, suffix="native"):
# Nothing found # Nothing found
if not package: if not package:
raise RuntimeError("Could not find dependency '" + pkgname_depend + raise RuntimeError(f"Could not find dependency '{pkgname_depend}' "
"' in any aports folder or APKINDEX. See:" "in any aports folder or APKINDEX. See:"
" <https://postmarketos.org/depends>") " <https://postmarketos.org/depends>")
# Append to todo/ret (unless it is a duplicate) # Append to todo/ret (unless it is a duplicate)
pkgname = package["pkgname"] pkgname = package["pkgname"]
if pkgname in ret: if pkgname in ret:
logging.verbose(pkgname + ": already found") logging.verbose(f"{pkgname}: already found")
else: else:
depends = package["depends"] depends = package["depends"]
logging.verbose(pkgname + ": depends on: " + ",".join(depends)) logging.verbose(f"{pkgname}: depends on: {','.join(depends)}")
if depends: if depends:
todo += depends todo += depends
ret.append(pkgname) ret.append(pkgname)

View File

@ -31,7 +31,8 @@ def is_in_array(config, option, string):
return False return False
def check_option(component, details, config, config_path_pretty, option, option_value): def check_option(component, details, config, config_path_pretty, option,
option_value):
link = (f"https://wiki.postmarketos.org/wiki/kconfig#CONFIG_{option}") link = (f"https://wiki.postmarketos.org/wiki/kconfig#CONFIG_{option}")
warning_no_details = (f"WARNING: {config_path_pretty} isn't" warning_no_details = (f"WARNING: {config_path_pretty} isn't"
f" configured properly for {component}, run" f" configured properly for {component}, run"
@ -86,15 +87,16 @@ def check_config(config_path, config_path_pretty, config_arch, pkgver,
for archs, options in archs_options.items(): for archs, options in archs_options.items():
if archs != "all": if archs != "all":
# Split and check if the device's architecture architecture has special config # Split and check if the device's architecture architecture has
# options. If option does not contain the architecture of the device # special config options. If option does not contain the
# kernel, then just skip the option. # architecture of the device kernel, then just skip the option.
architectures = archs.split(" ") architectures = archs.split(" ")
if config_arch not in architectures: if config_arch not in architectures:
continue continue
for option, option_value in options.items(): for option, option_value in options.items():
if not check_option(component, details, config, config_path_pretty, option, option_value): if not check_option(component, details, config,
config_path_pretty, option, option_value):
ret = False ret = False
if not details: if not details:
break # do not give too much error messages break # do not give too much error messages
@ -120,12 +122,13 @@ def check(args, pkgname, force_anbox_check=False, details=False):
aport = pmb.helpers.pmaports.find(args, "linux-" + flavor) aport = pmb.helpers.pmaports.find(args, "linux-" + flavor)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD") apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
pkgver = apkbuild["pkgver"] pkgver = apkbuild["pkgver"]
check_anbox = force_anbox_check or ("pmb:kconfigcheck-anbox" in apkbuild["options"]) check_anbox = force_anbox_check or (
"pmb:kconfigcheck-anbox" in apkbuild["options"])
for config_path in glob.glob(aport + "/config-*"): for config_path in glob.glob(aport + "/config-*"):
# The architecture of the config is in the name, so it just needs to be # The architecture of the config is in the name, so it just needs to be
# extracted # extracted
config_arch = os.path.basename(config_path).split(".")[1] config_arch = os.path.basename(config_path).split(".")[1]
config_path_pretty = "linux-" + flavor + "/" + os.path.basename(config_path) config_path_pretty = f"linux-{flavor}/{os.path.basename(config_path)}"
ret &= check_config(config_path, config_path_pretty, config_arch, ret &= check_config(config_path, config_path_pretty, config_arch,
pkgver, details=details) pkgver, details=details)
if check_anbox: if check_anbox:
@ -174,11 +177,11 @@ def check_file(args, config_file, anbox=False, details=False):
""" """
arch = extract_arch(config_file) arch = extract_arch(config_file)
version = extract_version(config_file) version = extract_version(config_file)
logging.debug("Check kconfig: parsed arch=" + arch + ", version=" + logging.debug(f"Check kconfig: parsed arch={arch}, version={version} from "
version + " from file: " + config_file) "file: {config_file}")
ret = check_config(config_file, config_file, arch, version, anbox=False, ret = check_config(config_file, config_file, arch, version, anbox=False,
details=details) details=details)
if anbox: if anbox:
ret &= check_config(config_file, config_file, arch, version, anbox=True, ret &= check_config(config_file, config_file, arch, version,
details=details) anbox=True, details=details)
return ret return ret

View File

@ -97,8 +97,11 @@ py_files="
pmb/parse/arch.py pmb/parse/arch.py
pmb/parse/arguments.py pmb/parse/arguments.py
pmb/parse/binfmt_info.py pmb/parse/binfmt_info.py
pmb/parse/bootimg.py
pmb/parse/cpuinfo.py pmb/parse/cpuinfo.py
pmb/parse/depends.py
pmb/parse/deviceinfo.py pmb/parse/deviceinfo.py
pmb/parse/kconfig.py
pmb/parse/version.py pmb/parse/version.py
pmb/qemu/__init__.py pmb/qemu/__init__.py
pmb/sideload/__init__.py pmb/sideload/__init__.py
@ -132,6 +135,7 @@ py_files="
test/test_newapkbuild.py test/test_newapkbuild.py
test/test_parse_apkbuild.py test/test_parse_apkbuild.py
test/test_parse_apkindex.py test/test_parse_apkindex.py
test/test_parse_depends.py
test/test_parse_deviceinfo.py test/test_parse_deviceinfo.py
test/test_questions.py test/test_questions.py
test/test_run_core.py test/test_run_core.py

View File

@ -75,7 +75,8 @@ def test_package_provider(args, monkeypatch):
# 5. Pick package with highest priority # 5. Pick package with highest priority
package_with_priority = {"pkgname": "test-priority", "provides": ["test"], package_with_priority = {"pkgname": "test-priority", "provides": ["test"],
"provider_priority": 100} "provider_priority": 100}
providers = {"test-two": package_two, "test-priority": package_with_priority} providers = {"test-two": package_two,
"test-priority": package_with_priority}
assert func(args, pkgname, pkgnames_install) == package_with_priority assert func(args, pkgname, pkgnames_install) == package_with_priority
# 6. Pick the first one # 6. Pick the first one