enforce E501 in pmb/helpers (MR 2058)
This commit is contained in:
parent
2b8efb996b
commit
039552f5b7
|
@ -27,7 +27,8 @@ class ReadlineTabCompleter:
|
|||
# First time: build match list
|
||||
if iteration == 0:
|
||||
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:
|
||||
self.matches = self.options[:]
|
||||
|
||||
|
@ -42,7 +43,8 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
|
|||
"""
|
||||
Ask a question on the terminal.
|
||||
: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 lowercase_answer: if True, convert return value to lower case
|
||||
: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:
|
||||
delims = delims.replace('-', '')
|
||||
readline.set_completer_delims(delims)
|
||||
readline.set_completer(ReadlineTabCompleter(complete).completer_func)
|
||||
readline.set_completer(
|
||||
ReadlineTabCompleter(complete).completer_func)
|
||||
|
||||
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.
|
||||
|
||||
: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"
|
||||
"""
|
||||
default_str = "y" if default else "n"
|
||||
|
|
|
@ -58,7 +58,7 @@ def list_apkbuilds(args):
|
|||
"""
|
||||
ret = {}
|
||||
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)
|
||||
return ret
|
||||
|
||||
|
|
|
@ -40,14 +40,16 @@ def _parse_flavor(args, autoinstall=True):
|
|||
"""
|
||||
# Install at least one kernel and get installed flavors
|
||||
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
|
||||
flavor = args.flavor
|
||||
if flavor:
|
||||
if flavor not in flavors:
|
||||
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
|
||||
" Run 'pmbootstrap flasher list_flavors' to get a list.")
|
||||
raise RuntimeError(f"No kernel installed with flavor {flavor}!" +
|
||||
" Run 'pmbootstrap flasher list_flavors' to"
|
||||
" get a list.")
|
||||
return flavor
|
||||
if not len(flavors):
|
||||
raise RuntimeError(
|
||||
|
@ -104,7 +106,8 @@ def build(args):
|
|||
return
|
||||
|
||||
# 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
|
||||
if src and not os.path.exists(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.")
|
||||
value = pmb.config.defaults[args.name]
|
||||
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)
|
||||
elif args.value is not None:
|
||||
cfg["pmbootstrap"][args.name] = args.value
|
||||
|
@ -228,7 +231,8 @@ def initfs(args):
|
|||
|
||||
def install(args):
|
||||
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:
|
||||
raise ValueError("Installation using rsync is not compatible with full"
|
||||
" disk encryption.")
|
||||
|
@ -391,7 +395,8 @@ def kconfig(args):
|
|||
packages.sort()
|
||||
for package in packages:
|
||||
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)
|
||||
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
|
||||
if "!pmb:kconfigcheck" in apkbuild["options"]:
|
||||
|
@ -542,7 +547,8 @@ def zap(args):
|
|||
def bootimg_analyze(args):
|
||||
bootimg = pmb.parse.bootimg(args, args.path)
|
||||
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()
|
||||
logging.info(tmp_output)
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ def download(args, url, prefix, cache=True, loglevel=logging.INFO,
|
|||
|
||||
# Offline and not cached
|
||||
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
|
||||
logging.log(loglevel, "Download " + url)
|
||||
|
@ -87,6 +88,6 @@ def retrieve(url, headers=None, allow_404=False):
|
|||
|
||||
|
||||
def retrieve_json(*args, **kwargs):
|
||||
""" Fetch the contents of a URL, parse it as JSON and return it. See retrieve() for the
|
||||
list of all parameters. """
|
||||
""" Fetch the contents of a URL, parse it as JSON and return it. See
|
||||
retrieve() for the list of all parameters. """
|
||||
return json.loads(retrieve(*args, **kwargs))
|
||||
|
|
|
@ -49,8 +49,9 @@ def add_verbose_log_level():
|
|||
logging.addLevelName(logging.VERBOSE, "VERBOSE")
|
||||
logging.Logger.verbose = lambda inst, msg, * \
|
||||
args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
|
||||
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg,
|
||||
*args, **kwargs)
|
||||
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE,
|
||||
msg, *args,
|
||||
**kwargs)
|
||||
|
||||
|
||||
def init(args):
|
||||
|
|
|
@ -56,7 +56,8 @@ def check_binfmt_misc(args):
|
|||
return
|
||||
|
||||
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):
|
||||
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
|
||||
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 True
|
||||
|
|
|
@ -112,8 +112,8 @@ def auto(args, dry=False):
|
|||
origin = apk["origin"]
|
||||
# Only increase once!
|
||||
if origin in ret:
|
||||
logging.verbose("{}: origin '{}' found again".format(pkgname,
|
||||
origin))
|
||||
logging.verbose(
|
||||
f"{pkgname}: origin '{origin}' found again")
|
||||
continue
|
||||
aport_path = pmb.helpers.pmaports.find(args, origin, False)
|
||||
if not aport_path:
|
||||
|
|
|
@ -27,7 +27,8 @@ def _find_apkbuilds(args):
|
|||
"subfolders. Please put it only in one folder.")
|
||||
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()))
|
||||
|
||||
# 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 must_exist: raise an exception when it can't be found
|
||||
:param subpackages: also search for subpackages with the specified names
|
||||
(slow! might need to parse all APKBUILDs to find it)
|
||||
:param subpackages: also search for subpackages with the specified
|
||||
names (slow! might need to parse all APKBUILDs to
|
||||
find it)
|
||||
:returns: relevant variables from the APKBUILD as dictionary, e.g.:
|
||||
{ "pkgname": "hello-world",
|
||||
"arch": ["all"],
|
||||
|
@ -189,7 +191,8 @@ def get(args, pkgname, must_exist=True, subpackages=True):
|
|||
if path:
|
||||
return pmb.parse.apkbuild(args, path)
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
(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))
|
||||
|
||||
# Prevent setting the check parameter with output="background".
|
||||
|
|
Loading…
Reference in New Issue