pmb.config.init: parse deviceinfo only once (MR 2132)
Instead of parsing the deviceinfo over and over again, parse it once and pass it to all the functions that make use of it.
This commit is contained in:
parent
05f257295d
commit
9d724d5d3d
|
@ -111,8 +111,7 @@ def ask_for_channel(args):
|
|||
" from the list above.")
|
||||
|
||||
|
||||
def ask_for_ui(args, device):
|
||||
info = pmb.parse.deviceinfo(args, device)
|
||||
def ask_for_ui(args, info):
|
||||
ui_list = pmb.helpers.ui.list(args, info["arch"])
|
||||
hidden_ui_count = 0
|
||||
device_is_accelerated = info.get("gpu_accelerated") == "true"
|
||||
|
@ -163,8 +162,7 @@ def ask_for_ui_extras(args, ui):
|
|||
default=args.ui_extras)
|
||||
|
||||
|
||||
def ask_for_keymaps(args, device):
|
||||
info = pmb.parse.deviceinfo(args, device)
|
||||
def ask_for_keymaps(args, info):
|
||||
if "keymaps" not in info or info["keymaps"].strip() == "":
|
||||
return ""
|
||||
options = info["keymaps"].split(' ')
|
||||
|
@ -568,16 +566,18 @@ def frontend(args):
|
|||
cfg["pmbootstrap"]["nonfree_firmware"] = str(nonfree["firmware"])
|
||||
cfg["pmbootstrap"]["nonfree_userland"] = str(nonfree["userland"])
|
||||
|
||||
info = pmb.parse.deviceinfo(args, device)
|
||||
|
||||
# Device keymap
|
||||
if device_exists:
|
||||
cfg["pmbootstrap"]["keymap"] = ask_for_keymaps(args, device)
|
||||
cfg["pmbootstrap"]["keymap"] = ask_for_keymaps(args, info)
|
||||
|
||||
# Username
|
||||
cfg["pmbootstrap"]["user"] = pmb.helpers.cli.ask("Username", None,
|
||||
args.user, False,
|
||||
"[a-z_][a-z0-9_-]*")
|
||||
# UI and various build options
|
||||
ui = ask_for_ui(args, device)
|
||||
ui = ask_for_ui(args, info)
|
||||
cfg["pmbootstrap"]["ui"] = ui
|
||||
cfg["pmbootstrap"]["ui_extras"] = str(ask_for_ui_extras(args, ui))
|
||||
ask_for_additional_options(args, cfg)
|
||||
|
@ -619,7 +619,7 @@ def frontend(args):
|
|||
pmb.helpers.cli.confirm(
|
||||
args, "Zap existing chroots to apply configuration?",
|
||||
default=True)):
|
||||
setattr(args, "deviceinfo", pmb.parse.deviceinfo(args, device=device))
|
||||
setattr(args, "deviceinfo", info)
|
||||
|
||||
# Do not zap any existing packages or cache_http directories
|
||||
pmb.chroot.zap(args, confirm=False)
|
||||
|
|
|
@ -11,6 +11,7 @@ import pmb.aportgen.device
|
|||
import pmb.config
|
||||
import pmb.config.init
|
||||
import pmb.helpers.logging
|
||||
import pmb.parse.deviceinfo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -211,19 +212,20 @@ def test_questions_flash_methods(args, monkeypatch):
|
|||
def test_questions_keymaps(args, monkeypatch):
|
||||
func = pmb.config.init.ask_for_keymaps
|
||||
fake_answers(monkeypatch, ["invalid_keymap", "us/rx51_us"])
|
||||
assert func(args, "nokia-n900") == "us/rx51_us"
|
||||
assert func(args, "lg-mako") == ""
|
||||
assert func(args, pmb.parse.deviceinfo(args, "nokia-n900")) == "us/rx51_us"
|
||||
assert func(args, pmb.parse.deviceinfo(args, "lg-mako")) == ""
|
||||
|
||||
|
||||
def test_questions_ui(args, monkeypatch):
|
||||
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
||||
device = "lg-mako"
|
||||
info = pmb.parse.deviceinfo(args, device)
|
||||
|
||||
fake_answers(monkeypatch, ["none"])
|
||||
assert pmb.config.init.ask_for_ui(args, device) == "none"
|
||||
assert pmb.config.init.ask_for_ui(args, info) == "none"
|
||||
|
||||
fake_answers(monkeypatch, ["invalid_UI", "weston"])
|
||||
assert pmb.config.init.ask_for_ui(args, device) == "weston"
|
||||
assert pmb.config.init.ask_for_ui(args, info) == "weston"
|
||||
|
||||
|
||||
def test_questions_ui_extras(args, monkeypatch):
|
||||
|
|
Loading…
Reference in New Issue