enforce E501 in pmb/helpers (MR 2058)

This commit is contained in:
Caio Fontes 2021-05-19 15:36:24 -03:00 committed by Oliver Smith
parent 2b8efb996b
commit 039552f5b7
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
9 changed files with 45 additions and 27 deletions

View File

@ -27,7 +27,8 @@ class ReadlineTabCompleter:
# First time: build match list # First time: build match list
if iteration == 0: if iteration == 0:
if input_text: if input_text:
self.matches = [s for s in self.options if s and s.startswith(input_text)] self.matches = [s for s in self.options
if s and s.startswith(input_text)]
else: else:
self.matches = self.options[:] self.matches = self.options[:]
@ -42,7 +43,8 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
""" """
Ask a question on the terminal. Ask a question on the terminal.
:param question: display prompt :param question: display prompt
:param choices: short list of possible answers, displayed after prompt if set :param choices: short list of possible answers,
displayed after prompt if set
:param default: default value to return if user doesn't input anything :param default: default value to return if user doesn't input anything
:param lowercase_answer: if True, convert return value to lower case :param lowercase_answer: if True, convert return value to lower case
:param validation_regex: if set, keep asking until regex matches :param validation_regex: if set, keep asking until regex matches
@ -62,7 +64,8 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
if '-' in delims: if '-' in delims:
delims = delims.replace('-', '') delims = delims.replace('-', '')
readline.set_completer_delims(delims) readline.set_completer_delims(delims)
readline.set_completer(ReadlineTabCompleter(complete).completer_func) readline.set_completer(
ReadlineTabCompleter(complete).completer_func)
ret = input(question_full + ": ") ret = input(question_full + ": ")
@ -95,7 +98,8 @@ def confirm(args, question="Continue?", default=False, no_assumptions=False):
""" """
Convenience wrapper around ask for simple yes-no questions with validation. Convenience wrapper around ask for simple yes-no questions with validation.
:param no_assumptions: ask for confirmation, even if "pmbootstrap -y' is set :param no_assumptions: ask for confirmation, even if "pmbootstrap -y'
is set
:returns: True for "y", False for "n" :returns: True for "y", False for "n"
""" """
default_str = "y" if default else "n" default_str = "y" if default else "n"

View File

@ -58,7 +58,7 @@ def list_apkbuilds(args):
""" """
ret = {} ret = {}
for device in list_codenames(args): for device in list_codenames(args):
apkbuild_path = args.aports + "/device/*/device-" + device + "/APKBUILD" apkbuild_path = f"{args.aports}/device/*/device-{device}/APKBUILD"
ret[device] = pmb.parse.apkbuild(args, apkbuild_path) ret[device] = pmb.parse.apkbuild(args, apkbuild_path)
return ret return ret

View File

@ -40,14 +40,16 @@ def _parse_flavor(args, autoinstall=True):
""" """
# Install at least one kernel and get installed flavors # Install at least one kernel and get installed flavors
suffix = "rootfs_" + args.device suffix = "rootfs_" + args.device
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix, autoinstall) flavors = pmb.chroot.other.kernel_flavors_installed(
args, suffix, autoinstall)
# Parse and verify the flavor argument # Parse and verify the flavor argument
flavor = args.flavor flavor = args.flavor
if flavor: if flavor:
if flavor not in flavors: if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" + raise RuntimeError(f"No kernel installed with flavor {flavor}!" +
" Run 'pmbootstrap flasher list_flavors' to get a list.") " Run 'pmbootstrap flasher list_flavors' to"
" get a list.")
return flavor return flavor
if not len(flavors): if not len(flavors):
raise RuntimeError( raise RuntimeError(
@ -104,7 +106,8 @@ def build(args):
return return
# Set src and force # Set src and force
src = os.path.realpath(os.path.expanduser(args.src[0])) if args.src else None src = os.path.realpath(os.path.expanduser(args.src[0])) \
if args.src else None
force = True if src else args.force force = True if src else args.force
if src and not os.path.exists(src): if src and not os.path.exists(src):
raise RuntimeError("Invalid path specified for --src: " + src) raise RuntimeError("Invalid path specified for --src: " + src)
@ -196,7 +199,7 @@ def config(args):
raise RuntimeError("config --reset requires a name to be given.") raise RuntimeError("config --reset requires a name to be given.")
value = pmb.config.defaults[args.name] value = pmb.config.defaults[args.name]
cfg["pmbootstrap"][args.name] = value cfg["pmbootstrap"][args.name] = value
logging.info("Config changed to default: " + args.name + "='" + value + "'") logging.info(f"Config changed to default: {args.name}='{value}'")
pmb.config.save(args, cfg) pmb.config.save(args, cfg)
elif args.value is not None: elif args.value is not None:
cfg["pmbootstrap"][args.name] = args.value cfg["pmbootstrap"][args.name] = args.value
@ -228,7 +231,8 @@ def initfs(args):
def install(args): def install(args):
if args.no_fde: if args.no_fde:
logging.warning("WARNING: --no-fde is deprecated, as it is now the default.") logging.warning("WARNING: --no-fde is deprecated,"
" as it is now the default.")
if args.rsync and args.full_disk_encryption: if args.rsync and args.full_disk_encryption:
raise ValueError("Installation using rsync is not compatible with full" raise ValueError("Installation using rsync is not compatible with full"
" disk encryption.") " disk encryption.")
@ -391,7 +395,8 @@ def kconfig(args):
packages.sort() packages.sort()
for package in packages: for package in packages:
if not args.force: if not args.force:
pkgname = package if package.startswith("linux-") else "linux-" + package pkgname = package if package.startswith("linux-") \
else "linux-" + package
aport = pmb.helpers.pmaports.find(args, pkgname) aport = pmb.helpers.pmaports.find(args, pkgname)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD") apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
if "!pmb:kconfigcheck" in apkbuild["options"]: if "!pmb:kconfigcheck" in apkbuild["options"]:
@ -542,7 +547,8 @@ def zap(args):
def bootimg_analyze(args): def bootimg_analyze(args):
bootimg = pmb.parse.bootimg(args, args.path) bootimg = pmb.parse.bootimg(args, args.path)
tmp_output = "Put these variables in the deviceinfo file of your device:\n" tmp_output = "Put these variables in the deviceinfo file of your device:\n"
for line in pmb.aportgen.device.generate_deviceinfo_fastboot_content(args, bootimg).split("\n"): for line in pmb.aportgen.device.\
generate_deviceinfo_fastboot_content(args, bootimg).split("\n"):
tmp_output += "\n" + line.lstrip() tmp_output += "\n" + line.lstrip()
logging.info(tmp_output) logging.info(tmp_output)

View File

@ -40,7 +40,8 @@ def download(args, url, prefix, cache=True, loglevel=logging.INFO,
# Offline and not cached # Offline and not cached
if args.offline: if args.offline:
raise RuntimeError(f"File not found in cache and offline flag is enabled: {url}") raise RuntimeError("File not found in cache and offline flag is"
f" enabled: {url}")
# Download the file # Download the file
logging.log(loglevel, "Download " + url) logging.log(loglevel, "Download " + url)
@ -87,6 +88,6 @@ def retrieve(url, headers=None, allow_404=False):
def retrieve_json(*args, **kwargs): def retrieve_json(*args, **kwargs):
""" Fetch the contents of a URL, parse it as JSON and return it. See retrieve() for the """ Fetch the contents of a URL, parse it as JSON and return it. See
list of all parameters. """ retrieve() for the list of all parameters. """
return json.loads(retrieve(*args, **kwargs)) return json.loads(retrieve(*args, **kwargs))

View File

@ -49,8 +49,9 @@ def add_verbose_log_level():
logging.addLevelName(logging.VERBOSE, "VERBOSE") logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.Logger.verbose = lambda inst, msg, * \ logging.Logger.verbose = lambda inst, msg, * \
args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs) args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE,
*args, **kwargs) msg, *args,
**kwargs)
def init(args): def init(args):

View File

@ -56,7 +56,8 @@ def check_binfmt_misc(args):
return return
pmb.helpers.run.root(args, ["modprobe", "binfmt_misc"], check=False) pmb.helpers.run.root(args, ["modprobe", "binfmt_misc"], check=False)
pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none", "/proc/sys/fs/binfmt_misc"]) pmb.helpers.run.root(args, ["mount", "-t", "binfmt_misc", "none",
"/proc/sys/fs/binfmt_misc"])
if not os.path.exists(path): if not os.path.exists(path):
link = "https://postmarketos.org/binfmt_misc" link = "https://postmarketos.org/binfmt_misc"
@ -271,6 +272,7 @@ def validate_hostname(hostname):
# Check that doesn't begin or end with a minus sign # Check that doesn't begin or end with a minus sign
if hostname[:1] == "-" or hostname[-1:] == "-": if hostname[:1] == "-" or hostname[-1:] == "-":
logging.fatal("ERROR: Hostname must not begin or end with a minus sign") logging.fatal("ERROR: Hostname must not begin or end with a minus"
" sign")
return False return False
return True return True

View File

@ -112,8 +112,8 @@ def auto(args, dry=False):
origin = apk["origin"] origin = apk["origin"]
# Only increase once! # Only increase once!
if origin in ret: if origin in ret:
logging.verbose("{}: origin '{}' found again".format(pkgname, logging.verbose(
origin)) f"{pkgname}: origin '{origin}' found again")
continue continue
aport_path = pmb.helpers.pmaports.find(args, origin, False) aport_path = pmb.helpers.pmaports.find(args, origin, False)
if not aport_path: if not aport_path:

View File

@ -27,7 +27,8 @@ def _find_apkbuilds(args):
"subfolders. Please put it only in one folder.") "subfolders. Please put it only in one folder.")
apkbuilds[package] = apkbuild apkbuilds[package] = apkbuild
# Sort dictionary so we don't need to do it over and over again in get_list() # Sort dictionary so we don't need to do it over and over again in
# get_list()
apkbuilds = dict(sorted(apkbuilds.items())) apkbuilds = dict(sorted(apkbuilds.items()))
# Save result in cache # Save result in cache
@ -170,8 +171,9 @@ def get(args, pkgname, must_exist=True, subpackages=True):
:param pkgname: the package name to find :param pkgname: the package name to find
:param must_exist: raise an exception when it can't be found :param must_exist: raise an exception when it can't be found
:param subpackages: also search for subpackages with the specified names :param subpackages: also search for subpackages with the specified
(slow! might need to parse all APKBUILDs to find it) names (slow! might need to parse all APKBUILDs to
find it)
:returns: relevant variables from the APKBUILD as dictionary, e.g.: :returns: relevant variables from the APKBUILD as dictionary, e.g.:
{ "pkgname": "hello-world", { "pkgname": "hello-world",
"arch": ["all"], "arch": ["all"],
@ -189,7 +191,8 @@ def get(args, pkgname, must_exist=True, subpackages=True):
if path: if path:
return pmb.parse.apkbuild(args, path) return pmb.parse.apkbuild(args, path)
if must_exist: if must_exist:
raise RuntimeError(f"Could not find APKBUILD for package: {pkgname}") raise RuntimeError("Could not find APKBUILD for package:"
f" {pkgname}")
return None return None

View File

@ -20,7 +20,8 @@ def sanity_checks(output="log", output_return=False, check=None):
Raise an exception if the parameters passed to core() don't make sense Raise an exception if the parameters passed to core() don't make sense
(all parameters are described in core() below). (all parameters are described in core() below).
""" """
if output not in ["log", "stdout", "interactive", "tui", "background", "pipe"]: vals = ["log", "stdout", "interactive", "tui", "background", "pipe"]
if output not in vals:
raise RuntimeError("Invalid output value: " + str(output)) raise RuntimeError("Invalid output value: " + str(output))
# Prevent setting the check parameter with output="background". # Prevent setting the check parameter with output="background".