pmbootstrap init: only display UIs for device arch (MR 1937)

Hide user interfaces that are not available for the selected device's
architecture.

Closes #1790
This commit is contained in:
Anjandev Momi 2020-05-14 03:20:11 -07:00 committed by Oliver Smith
parent 2d2ab1df56
commit 0ff9c5d471
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
6 changed files with 55 additions and 7 deletions

View File

@ -105,8 +105,9 @@ def ask_for_channel(args):
" from the list above.")
def ask_for_ui(args):
ui_list = pmb.helpers.ui.list(args)
def ask_for_ui(args, device):
info = pmb.parse.deviceinfo(args, device)
ui_list = pmb.helpers.ui.list(args, info["arch"])
logging.info("Available user interfaces (" +
str(len(ui_list) - 1) + "): ")
ui_completion_list = []
@ -419,7 +420,7 @@ def frontend(args):
args.user, False,
"[a-z_][a-z0-9_-]*")
# UI and various build options
ui = ask_for_ui(args)
ui = ask_for_ui(args, device)
cfg["pmbootstrap"]["ui"] = ui
cfg["pmbootstrap"]["ui_extras"] = str(ask_for_ui_extras(args, ui))
ask_for_build_options(args, cfg)

View File

@ -5,15 +5,17 @@ import glob
import pmb.parse
def list(args):
def list(args, arch):
"""
Get all UIs, for which aports are available with their description.
:param arch: device architecture, for which the UIs must be available
:returns: [("none", "No graphical..."), ("weston", "Wayland reference...")]
"""
ret = [("none", "No graphical environment")]
for path in sorted(glob.glob(args.aports + "/main/postmarketos-ui-*")):
apkbuild = pmb.parse.apkbuild(args, path + "/APKBUILD")
ui = os.path.basename(path).split("-", 2)[2]
ret.append((ui, apkbuild["pkgdesc"]))
if pmb.helpers.package.check_arch(args, apkbuild["pkgname"], arch):
ret.append((ui, apkbuild["pkgdesc"]))
return ret

32
test/test_helpers_ui.py Normal file
View File

@ -0,0 +1,32 @@
# Copyright 2020 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest
import sys
import pmb_test
import pmb_test.const
import pmb.helpers.logging
import pmb.helpers.ui
@pytest.fixture
def args(tmpdir, request):
import pmb.parse
cfg = f"{pmb_test.const.testdata}/channels.cfg"
sys.argv = ["pmbootstrap.py", "--config-channels", cfg, "init"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(args.logfd.close)
return args
def test_helpers_ui(args):
""" Test the UIs returned by pmb.helpers.ui.list() with a testdata pmaports
dir. That test dir has a plasma-mobile UI, which is disabled for armhf,
so it must not be returned when querying the UI list for armhf. """
args.aports = f"{pmb_test.const.testdata}/helpers_ui/pmaports"
func = pmb.helpers.ui.list
assert func(args, "armhf") == [("none", "No graphical environment")]
assert func(args, "x86_64") == [("none", "No graphical environment"),
("plasma-mobile", "cool pkgdesc")]

View File

@ -216,12 +216,13 @@ def test_questions_keymaps(args, monkeypatch):
def test_questions_ui(args, monkeypatch):
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
device = "lg-mako"
fake_answers(monkeypatch, ["none"])
assert pmb.config.init.ask_for_ui(args) == "none"
assert pmb.config.init.ask_for_ui(args, device) == "none"
fake_answers(monkeypatch, ["invalid_UI", "weston"])
assert pmb.config.init.ask_for_ui(args) == "weston"
assert pmb.config.init.ask_for_ui(args, device) == "weston"
def test_questions_ui_extras(args, monkeypatch):

View File

@ -0,0 +1,11 @@
pkgname=postmarketos-ui-plasma-mobile
pkgver=42
pkgrel=0
pkgdesc="cool pkgdesc"
url="https://postmarketos.org"
arch="noarch !armhf"
license="GPL-3.0-or-later"
package() {
mkdir "$pkgdir"
}

View File

@ -0,0 +1 @@
../../pmaports.cfg