pmb/config/init.py: use f-strings, fix E501 (MR 2043)
This commit is contained in:
parent
08617722a4
commit
c347b27f69
|
@ -28,8 +28,8 @@ def require_programs():
|
||||||
missing.append(program)
|
missing.append(program)
|
||||||
if missing:
|
if missing:
|
||||||
raise RuntimeError("Can't find all programs required to run"
|
raise RuntimeError("Can't find all programs required to run"
|
||||||
" pmbootstrap. Please install first: " +
|
" pmbootstrap. Please install first:"
|
||||||
", ".join(missing))
|
f" {', '.join(missing)}")
|
||||||
|
|
||||||
|
|
||||||
def ask_for_work_path(args):
|
def ask_for_work_path(args):
|
||||||
|
@ -53,7 +53,7 @@ def ask_for_work_path(args):
|
||||||
|
|
||||||
# Work must not be inside the pmbootstrap path
|
# Work must not be inside the pmbootstrap path
|
||||||
if (work == pmb.config.pmb_src or
|
if (work == pmb.config.pmb_src or
|
||||||
work.startswith(pmb.config.pmb_src + "/")):
|
work.startswith(f"{pmb.config.pmb_src}/")):
|
||||||
logging.fatal("ERROR: The work path must not be inside the"
|
logging.fatal("ERROR: The work path must not be inside the"
|
||||||
" pmbootstrap path. Please specify another"
|
" pmbootstrap path. Please specify another"
|
||||||
" location.")
|
" location.")
|
||||||
|
@ -66,12 +66,12 @@ def ask_for_work_path(args):
|
||||||
if not os.listdir(work):
|
if not os.listdir(work):
|
||||||
# Directory is empty, either because we just created it or
|
# Directory is empty, either because we just created it or
|
||||||
# because user created it before running pmbootstrap init
|
# because user created it before running pmbootstrap init
|
||||||
with open(work + "/version", "w") as handle:
|
with open(f"{work}/version", "w") as handle:
|
||||||
handle.write(str(pmb.config.work_version) + "\n")
|
handle.write(f"{pmb.config.work_version}\n")
|
||||||
|
|
||||||
# Create cache_git dir, so it is owned by the host system's user
|
# Create cache_git dir, so it is owned by the host system's user
|
||||||
# (otherwise pmb.helpers.mount.bind would create it as root)
|
# (otherwise pmb.helpers.mount.bind would create it as root)
|
||||||
os.makedirs(work + "/cache_git", 0o700, True)
|
os.makedirs(f"{work}/cache_git", 0o700, True)
|
||||||
return (work, exists)
|
return (work, exists)
|
||||||
except OSError:
|
except OSError:
|
||||||
logging.fatal("ERROR: Could not create this folder, or write"
|
logging.fatal("ERROR: Could not create this folder, or write"
|
||||||
|
@ -147,17 +147,17 @@ def ask_for_ui(args, device):
|
||||||
|
|
||||||
|
|
||||||
def ask_for_ui_extras(args, ui):
|
def ask_for_ui_extras(args, ui):
|
||||||
apkbuild = pmb.helpers.pmaports.get(args, "postmarketos-ui-" + ui,
|
apkbuild = pmb.helpers.pmaports.get(args, f"postmarketos-ui-{ui}",
|
||||||
subpackages=False, must_exist=False)
|
subpackages=False, must_exist=False)
|
||||||
if not apkbuild:
|
if not apkbuild:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
extra = apkbuild["subpackages"].get("postmarketos-ui-" + ui + "-extras")
|
extra = apkbuild["subpackages"].get(f"postmarketos-ui-{ui}-extras")
|
||||||
if extra is None:
|
if extra is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logging.info("This user interface has an extra package: " +
|
logging.info("This user interface has an extra package:"
|
||||||
extra["pkgdesc"])
|
f" {extra['pkgdesc']}")
|
||||||
|
|
||||||
return pmb.helpers.cli.confirm(args, "Enable this package?",
|
return pmb.helpers.cli.confirm(args, "Enable this package?",
|
||||||
default=args.ui_extras)
|
default=args.ui_extras)
|
||||||
|
@ -168,8 +168,8 @@ def ask_for_keymaps(args, device):
|
||||||
if "keymaps" not in info or info["keymaps"].strip() == "":
|
if "keymaps" not in info or info["keymaps"].strip() == "":
|
||||||
return ""
|
return ""
|
||||||
options = info["keymaps"].split(' ')
|
options = info["keymaps"].split(' ')
|
||||||
logging.info("Available keymaps for device (" + str(len(options)) +
|
logging.info(f"Available keymaps for device ({len(options)}): "
|
||||||
"): " + ", ".join(options))
|
f"{', '.join(options)}")
|
||||||
if args.keymap == "":
|
if args.keymap == "":
|
||||||
args.keymap = options[0]
|
args.keymap = options[0]
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ def ask_for_timezone(args):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if tz:
|
if tz:
|
||||||
logging.info("Your host timezone: " + tz)
|
logging.info(f"Your host timezone: {tz}")
|
||||||
if pmb.helpers.cli.confirm(args,
|
if pmb.helpers.cli.confirm(args,
|
||||||
"Use this timezone instead of GMT?",
|
"Use this timezone instead of GMT?",
|
||||||
default="y"):
|
default="y"):
|
||||||
|
@ -237,9 +237,9 @@ def ask_for_device_kernel(args, device):
|
||||||
" downstream kernels.")
|
" downstream kernels.")
|
||||||
|
|
||||||
# List kernels
|
# List kernels
|
||||||
logging.info("Available kernels (" + str(len(kernels)) + "):")
|
logging.info(f"Available kernels ({len(kernels)}):")
|
||||||
for type in sorted(kernels.keys()):
|
for type in sorted(kernels.keys()):
|
||||||
logging.info("* " + type + ": " + kernels[type])
|
logging.info(f"* {type}: {kernels[type]}")
|
||||||
while True:
|
while True:
|
||||||
ret = pmb.helpers.cli.ask(args, "Kernel", None, default, True,
|
ret = pmb.helpers.cli.ask(args, "Kernel", None, default, True,
|
||||||
complete=kernels)
|
complete=kernels)
|
||||||
|
@ -271,7 +271,7 @@ def ask_for_device_nonfree(args, device):
|
||||||
# Only run when there is a "nonfree" subpackage
|
# Only run when there is a "nonfree" subpackage
|
||||||
nonfree_found = False
|
nonfree_found = False
|
||||||
for subpackage in apkbuild["subpackages"].keys():
|
for subpackage in apkbuild["subpackages"].keys():
|
||||||
if subpackage.startswith("device-" + device + "-nonfree"):
|
if subpackage.startswith(f"device-{device}-nonfree"):
|
||||||
nonfree_found = True
|
nonfree_found = True
|
||||||
if not nonfree_found:
|
if not nonfree_found:
|
||||||
return ret
|
return ret
|
||||||
|
@ -285,13 +285,13 @@ def ask_for_device_nonfree(args, device):
|
||||||
|
|
||||||
# Ask for firmware and userland individually
|
# Ask for firmware and userland individually
|
||||||
for type in ["firmware", "userland"]:
|
for type in ["firmware", "userland"]:
|
||||||
subpkgname = "device-" + device + "-nonfree-" + type
|
subpkgname = f"device-{device}-nonfree-{type}"
|
||||||
subpkg = apkbuild["subpackages"].get(subpkgname, {})
|
subpkg = apkbuild["subpackages"].get(subpkgname, {})
|
||||||
if subpkg is None:
|
if subpkg is None:
|
||||||
raise RuntimeError("Cannot find subpackage function for "
|
raise RuntimeError("Cannot find subpackage function for "
|
||||||
f"{subpkgname}")
|
f"{subpkgname}")
|
||||||
if subpkg:
|
if subpkg:
|
||||||
logging.info(subpkgname + ": " + subpkg["pkgdesc"])
|
logging.info(f"{subpkgname}: {subpkg['pkgdesc']}")
|
||||||
ret[type] = pmb.helpers.cli.confirm(args, "Enable this package?",
|
ret[type] = pmb.helpers.cli.confirm(args, "Enable this package?",
|
||||||
default=ret[type])
|
default=ret[type])
|
||||||
return ret
|
return ret
|
||||||
|
@ -301,8 +301,7 @@ def ask_for_device(args):
|
||||||
vendors = sorted(pmb.helpers.devices.list_vendors(args))
|
vendors = sorted(pmb.helpers.devices.list_vendors(args))
|
||||||
logging.info("Choose your target device vendor (either an "
|
logging.info("Choose your target device vendor (either an "
|
||||||
"existing one, or a new one for porting).")
|
"existing one, or a new one for porting).")
|
||||||
logging.info("Available vendors (" + str(len(vendors)) + "): " +
|
logging.info(f"Available vendors ({len(vendors)}): {', '.join(vendors)}")
|
||||||
", ".join(vendors))
|
|
||||||
|
|
||||||
current_vendor = None
|
current_vendor = None
|
||||||
current_codename = None
|
current_codename = None
|
||||||
|
@ -337,7 +336,7 @@ def ask_for_device(args):
|
||||||
current_codename, False, r"[a-z0-9]+",
|
current_codename, False, r"[a-z0-9]+",
|
||||||
codenames)
|
codenames)
|
||||||
|
|
||||||
device = vendor + '-' + codename
|
device = f"{vendor}-{codename}"
|
||||||
device_path = pmb.helpers.devices.find_path(args, device, 'deviceinfo')
|
device_path = pmb.helpers.devices.find_path(args, device, 'deviceinfo')
|
||||||
device_exists = device_path is not None
|
device_exists = device_path is not None
|
||||||
if not device_exists:
|
if not device_exists:
|
||||||
|
@ -346,18 +345,18 @@ def ask_for_device(args):
|
||||||
"This device does not exist anymore, check"
|
"This device does not exist anymore, check"
|
||||||
" <https://postmarketos.org/renamed>"
|
" <https://postmarketos.org/renamed>"
|
||||||
" to see if it was renamed")
|
" to see if it was renamed")
|
||||||
logging.info("You are about to do a new device port for '" +
|
logging.info("You are about to do"
|
||||||
device + "'.")
|
f" a new device port for '{device}'.")
|
||||||
if not pmb.helpers.cli.confirm(args, default=True):
|
if not pmb.helpers.cli.confirm(args, default=True):
|
||||||
current_vendor = vendor
|
current_vendor = vendor
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# New port creation confirmed
|
# New port creation confirmed
|
||||||
logging.info("Generating new aports for: {}...".format(device))
|
logging.info("Generating new aports for: {}...".format(device))
|
||||||
pmb.aportgen.generate(args, "device-" + device)
|
pmb.aportgen.generate(args, f"device-{device}")
|
||||||
pmb.aportgen.generate(args, "linux-" + device)
|
pmb.aportgen.generate(args, f"linux-{device}")
|
||||||
elif "/unmaintained/" in device_path:
|
elif "/unmaintained/" in device_path:
|
||||||
apkbuild = device_path[:-len("deviceinfo")] + 'APKBUILD'
|
apkbuild = f"{device_path[:-len('deviceinfo')]}APKBUILD"
|
||||||
unmaintained = pmb.parse._apkbuild.unmaintained(apkbuild)
|
unmaintained = pmb.parse._apkbuild.unmaintained(apkbuild)
|
||||||
logging.info(f"WARNING: {device} is unmaintained: {unmaintained}")
|
logging.info(f"WARNING: {device} is unmaintained: {unmaintained}")
|
||||||
if not pmb.helpers.cli.confirm(args):
|
if not pmb.helpers.cli.confirm(args):
|
||||||
|
|
Loading…
Reference in New Issue