pmb.config.init: 2-step device selection (!1825)
When running pmbootstrap init, first select device vendor, then device codename. Also fixed tests for new behavior and added some new ones for new scenarios.
This commit is contained in:
parent
a0a3a591da
commit
cd2180d178
|
@ -217,14 +217,41 @@ def ask_for_device_nonfree(args, device):
|
|||
|
||||
|
||||
def ask_for_device(args):
|
||||
devices = sorted(pmb.helpers.devices.list_codenames(args))
|
||||
logging.info("Target device (either an existing one, or a new one for"
|
||||
" porting).")
|
||||
logging.info("Available (" + str(len(devices)) + "): " +
|
||||
", ".join(devices))
|
||||
vendors = sorted(pmb.helpers.devices.list_vendors(args))
|
||||
logging.info("Choose your target device vendor (either an "
|
||||
"existing one, or a new one for porting).")
|
||||
logging.info("Available vendors (" + str(len(vendors)) + "): " +
|
||||
", ".join(vendors))
|
||||
|
||||
current_vendor = None
|
||||
current_codename = None
|
||||
if args.device:
|
||||
current_vendor = args.device.split("-", 1)[0]
|
||||
current_codename = args.device.split("-", 1)[1]
|
||||
|
||||
while True:
|
||||
device = pmb.helpers.cli.ask(args, "Device", None, args.device, False,
|
||||
"[a-z0-9]+-[a-z0-9]+")
|
||||
vendor = pmb.helpers.cli.ask(args, "Vendor", None, current_vendor,
|
||||
False, r"[a-z0-9]+")
|
||||
|
||||
new_vendor = vendor not in vendors
|
||||
if new_vendor:
|
||||
logging.info(f"The specified vendor ({vendor}) could not be found "
|
||||
f"in existing ports, do you want to start a new port?")
|
||||
if not pmb.helpers.cli.confirm(args, default=True):
|
||||
continue
|
||||
else:
|
||||
devices = sorted(pmb.helpers.devices.list_codenames(args, vendor))
|
||||
# Remove "vendor-" prefixes from device list
|
||||
codenames = [x.split('-', 1)[1] for x in devices]
|
||||
logging.info("Available codenames (" + str(len(codenames)) + "): " +
|
||||
", ".join(codenames))
|
||||
|
||||
if current_vendor != vendor:
|
||||
current_codename = ''
|
||||
codename = pmb.helpers.cli.ask(args, "Device codename", None,
|
||||
current_codename, False, r"[a-z0-9]+")
|
||||
|
||||
device = vendor + '-' + codename
|
||||
device_exists = os.path.exists(args.aports + "/device/device-" +
|
||||
device + "/deviceinfo")
|
||||
if not device_exists:
|
||||
|
@ -236,8 +263,11 @@ def ask_for_device(args):
|
|||
logging.info("You are about to do a new device port for '" +
|
||||
device + "'.")
|
||||
if not pmb.helpers.cli.confirm(args, default=True):
|
||||
current_vendor = vendor
|
||||
continue
|
||||
|
||||
# New port creation confirmed
|
||||
logging.info(f"Generating new aports for: {device}...")
|
||||
pmb.aportgen.generate(args, "device-" + device)
|
||||
pmb.aportgen.generate(args, "linux-" + device)
|
||||
break
|
||||
|
|
|
@ -21,15 +21,29 @@ import glob
|
|||
import pmb.parse
|
||||
|
||||
|
||||
def list_codenames(args):
|
||||
def list_codenames(args, vendor=None):
|
||||
"""
|
||||
Get all devices, for which aports are available
|
||||
:param vendor: vendor name to choose devices from, or None for all vendors
|
||||
:returns: ["first-device", "second-device", ...]
|
||||
"""
|
||||
ret = []
|
||||
for path in glob.glob(args.aports + "/device/device-*"):
|
||||
device = os.path.basename(path).split("-", 1)[1]
|
||||
ret += [device]
|
||||
if (vendor is None) or device.startswith(vendor + '-'):
|
||||
ret.append(device)
|
||||
return ret
|
||||
|
||||
|
||||
def list_vendors(args):
|
||||
"""
|
||||
Get all device vendors, for which aports are available
|
||||
:returns: {"vendor1", "vendor2", ...}
|
||||
"""
|
||||
ret = set()
|
||||
for path in glob.glob(args.aports + "/device/device-*"):
|
||||
vendor = os.path.basename(path).split("-", 2)[1]
|
||||
ret.add(vendor)
|
||||
return ret
|
||||
|
||||
|
||||
|
|
|
@ -134,18 +134,26 @@ def test_questions_device(args, monkeypatch):
|
|||
# Existing device (without non-free components so we have defaults there)
|
||||
func = pmb.config.init.ask_for_device
|
||||
nonfree = {"firmware": True, "userland": False}
|
||||
fake_answers(monkeypatch, ["lg-mako"])
|
||||
fake_answers(monkeypatch, ["lg", "mako"])
|
||||
kernel = args.kernel
|
||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
||||
|
||||
# Non-existing device, go back, existing device
|
||||
fake_answers(monkeypatch, ["whoops-typo", "n", "lg-mako"])
|
||||
# Non-existing vendor, go back, existing vendor+device
|
||||
fake_answers(monkeypatch, ["whoops", "n", "lg", "mako"])
|
||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
||||
|
||||
# New device
|
||||
fake_answers(monkeypatch, ["new-device", "y"])
|
||||
# Existing vendor, new device, go back, existing vendor+device
|
||||
fake_answers(monkeypatch, ["lg", "nonexistent", "n", "lg", "mako"])
|
||||
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
||||
|
||||
# New vendor and new device (new port)
|
||||
fake_answers(monkeypatch, ["new", "y", "device", "y"])
|
||||
assert func(args) == ("new-device", False, kernel, nonfree)
|
||||
|
||||
# Existing vendor, new device (new port)
|
||||
fake_answers(monkeypatch, ["lg", "nonexistent", "y"])
|
||||
assert func(args) == ("lg-nonexistent", False, kernel, nonfree)
|
||||
|
||||
|
||||
def test_questions_device_kernel(args, monkeypatch):
|
||||
# Prepare args
|
||||
|
|
Loading…
Reference in New Issue