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:
Alexey Min 2019-10-13 17:09:32 +03:00 committed by Oliver Smith
parent a0a3a591da
commit cd2180d178
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
3 changed files with 66 additions and 14 deletions

View file

@ -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