diff --git a/pmb/aportgen/device.py b/pmb/aportgen/device.py index 50973d04..e2b6786a 100644 --- a/pmb/aportgen/device.py +++ b/pmb/aportgen/device.py @@ -44,6 +44,15 @@ def ask_for_year(args): validation_regex=r'^[1-9]\d{3,}$') +def ask_for_chassis(args): + types = pmb.config.deviceinfo_chassis_types + + logging.info("What type of device is it?") + logging.info("Valid types are: " + ", ".join(types)) + return pmb.helpers.cli.ask(args, "Chassis", None, None, True, + validation_regex='|'.join(types), complete=types) + + def ask_for_keyboard(args): return pmb.helpers.cli.confirm(args, "Does the device have a hardware keyboard?") @@ -120,7 +129,7 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None): def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch, - has_keyboard, has_external_storage, + chassis, has_keyboard, has_external_storage, flash_method, bootimg=None): codename = "-".join(pkgname.split("-")[1:]) # Note: New variables must be added to pmb/config/__init__.py as well @@ -138,6 +147,7 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch, deviceinfo_arch="{arch}" # Device related + deviceinfo_chassis="{chassis}" deviceinfo_keyboard="{"true" if has_keyboard else "false"}" deviceinfo_external_storage="{"true" if has_external_storage else "false"}" deviceinfo_screen_width="800" @@ -232,6 +242,7 @@ def generate(args, pkgname): manufacturer = ask_for_manufacturer(args) name = ask_for_name(args, manufacturer) year = ask_for_year(args) + chassis = ask_for_chassis(args) has_keyboard = ask_for_keyboard(args) has_external_storage = ask_for_external_storage(args) flash_method = ask_for_flash_method(args) @@ -240,6 +251,6 @@ def generate(args, pkgname): bootimg = ask_for_bootimg(args) generate_deviceinfo(args, pkgname, name, manufacturer, year, arch, - has_keyboard, has_external_storage, + chassis, has_keyboard, has_external_storage, flash_method, bootimg) generate_apkbuild(args, pkgname, name, arch, flash_method) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 0246a54c..9c37a10d 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -304,6 +304,7 @@ deviceinfo_attributes = [ "arch", # device + "chassis", "keyboard", "external_storage", "screen_width", @@ -348,6 +349,20 @@ deviceinfo_attributes = [ "keymaps", ] +# Valid types for the 'chassis' atribute in deviceinfo +# See https://www.freedesktop.org/software/systemd/man/machine-info.html +deviceinfo_chassis_types = [ + "desktop", + "laptop", + "convertible", + "server", + "tablet", + "handset", + "watch", + "embedded", + "vm" +] + # # INITFS # diff --git a/test/test_aportgen_device_wizard.py b/test/test_aportgen_device_wizard.py index e17381ec..1b718eff 100644 --- a/test/test_aportgen_device_wizard.py +++ b/test/test_aportgen_device_wizard.py @@ -54,7 +54,7 @@ def generate(args, monkeypatch, answers): """ # Patched function def fake_ask(args, question="Continue?", choices=["y", "n"], default="n", - lowercase_answer=True, validation_regex=None): + lowercase_answer=True, validation_regex=None, complete=None): for substr, answer in answers.items(): if substr in question: logging.info(question + ": " + answer) @@ -117,6 +117,7 @@ def test_aportgen_device_wizard(args, monkeypatch): "Manufacturer": "Testsuite", "Name": "Testsuite Testdevice", "Year": "1337", + "Chassis": "handset", "Type": "isorec", } @@ -137,6 +138,7 @@ def test_aportgen_device_wizard(args, monkeypatch): assert deviceinfo["manufacturer"] == answers["Manufacturer"] assert deviceinfo["arch"] == "armhf" assert deviceinfo["year"] == "1337" + assert deviceinfo["chassis"] == "handset" assert deviceinfo["keyboard"] == "false" assert deviceinfo["external_storage"] == "true" assert deviceinfo["flash_method"] == "heimdall-isorec" diff --git a/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo b/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo index 577483ad..0d986394 100644 --- a/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo +++ b/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo @@ -12,6 +12,7 @@ deviceinfo_flash_method="fastboot" deviceinfo_arch="armhf" # Device related +deviceinfo_chassis="handset" deviceinfo_keyboard="false" deviceinfo_screen_width="768" deviceinfo_screen_height="1280"