diff --git a/pmb/config/init.py b/pmb/config/init.py index 5991f468..d12ce5eb 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -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) diff --git a/pmb/helpers/ui.py b/pmb/helpers/ui.py index b903cbcb..e76978f4 100644 --- a/pmb/helpers/ui.py +++ b/pmb/helpers/ui.py @@ -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 diff --git a/test/test_helpers_ui.py b/test/test_helpers_ui.py new file mode 100644 index 00000000..2c4d6b75 --- /dev/null +++ b/test/test_helpers_ui.py @@ -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")] diff --git a/test/test_questions.py b/test/test_questions.py index cc373266..d446c4f7 100644 --- a/test/test_questions.py +++ b/test/test_questions.py @@ -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): diff --git a/test/testdata/helpers_ui/pmaports/main/postmarketos-ui-plasma-mobile/APKBUILD b/test/testdata/helpers_ui/pmaports/main/postmarketos-ui-plasma-mobile/APKBUILD new file mode 100644 index 00000000..434a0eaf --- /dev/null +++ b/test/testdata/helpers_ui/pmaports/main/postmarketos-ui-plasma-mobile/APKBUILD @@ -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" +} diff --git a/test/testdata/helpers_ui/pmaports/pmaports.cfg b/test/testdata/helpers_ui/pmaports/pmaports.cfg new file mode 120000 index 00000000..df27c9da --- /dev/null +++ b/test/testdata/helpers_ui/pmaports/pmaports.cfg @@ -0,0 +1 @@ +../../pmaports.cfg \ No newline at end of file