pmb: replace deviceinfo_date with deviceinfo_year, add to wizard (!1888)

See: https://gitlab.com/postmarketOS/pmaports/issues/447
This commit is contained in:
Minecrell 2020-03-07 15:44:52 +01:00 committed by Oliver Smith
parent 2159a083ef
commit 0997a46b3a
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
5 changed files with 23 additions and 7 deletions

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
import pmb.helpers.cli
import pmb.helpers.run
import pmb.aportgen.core
import pmb.parse.apkindex
@ -36,6 +37,13 @@ def ask_for_name(args, manufacturer):
return ret
def ask_for_year(args):
# Regex from https://stackoverflow.com/a/12240826
logging.info("In what year was the device released (e.g. 2012)?")
return pmb.helpers.cli.ask(args, "Year", None, None, False,
validation_regex=r'^[1-9]\d{3,}$')
def ask_for_keyboard(args):
return pmb.helpers.cli.confirm(args, "Does the device have a hardware keyboard?")
@ -111,8 +119,9 @@ def generate_deviceinfo_fastboot_content(args, bootimg=None):
"""
def generate_deviceinfo(args, pkgname, name, manufacturer, arch, has_keyboard,
has_external_storage, flash_method, bootimg=None):
def generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
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
content = """\
@ -123,7 +132,7 @@ def generate_deviceinfo(args, pkgname, name, manufacturer, arch, has_keyboard,
deviceinfo_name=\"""" + name + """\"
deviceinfo_manufacturer=\"""" + manufacturer + """\"
deviceinfo_codename=\"""" + codename + """\"
deviceinfo_date=""
deviceinfo_year=\"""" + year + """\"
deviceinfo_dtb=""
deviceinfo_modules_initfs=""
deviceinfo_arch=\"""" + arch + """\"
@ -224,6 +233,7 @@ def generate(args, pkgname):
arch = ask_for_architecture(args)
manufacturer = ask_for_manufacturer(args)
name = ask_for_name(args, manufacturer)
year = ask_for_year(args)
has_keyboard = ask_for_keyboard(args)
has_external_storage = ask_for_external_storage(args)
flash_method = ask_for_flash_method(args)
@ -231,6 +241,7 @@ def generate(args, pkgname):
if flash_method in ["fastboot", "heimdall-bootimg"]:
bootimg = ask_for_bootimg(args)
generate_deviceinfo(args, pkgname, name, manufacturer, arch, has_keyboard,
has_external_storage, flash_method, bootimg)
generate_deviceinfo(args, pkgname, name, manufacturer, year, arch,
has_keyboard, has_external_storage,
flash_method, bootimg)
generate_apkbuild(args, pkgname, name, arch, flash_method)

View File

@ -252,7 +252,7 @@ deviceinfo_attributes = [
"name",
"manufacturer",
"codename",
"date",
"year",
"dtb",
"modules_initfs",
"arch",

View File

@ -37,6 +37,9 @@ def sanity_check(info, path):
if "dev_keyboard" in info:
raise RuntimeError("deviceinfo_dev_keyboard is unused. "
"Please delete it in: " + path)
if "date" in info:
raise RuntimeError("deviceinfo_date was replaced by deviceinfo_year. "
"Set it to the release year in: " + path)
# "codename" is required
codename = os.path.basename(os.path.dirname(path))

View File

@ -110,6 +110,7 @@ def test_aportgen_device_wizard(args, monkeypatch):
"Flash method": "heimdall",
"Manufacturer": "Testsuite",
"Name": "Testsuite Testdevice",
"Year": "1337",
"Type": "isorec",
}
@ -129,6 +130,7 @@ def test_aportgen_device_wizard(args, monkeypatch):
assert deviceinfo["name"] == "Testsuite Testdevice"
assert deviceinfo["manufacturer"] == answers["Manufacturer"]
assert deviceinfo["arch"] == "armhf"
assert deviceinfo["year"] == "1337"
assert deviceinfo["keyboard"] == "false"
assert deviceinfo["external_storage"] == "true"
assert deviceinfo["flash_method"] == "heimdall-isorec"

View File

@ -4,7 +4,7 @@
deviceinfo_format_version="0"
deviceinfo_name="Google Nexus 4"
deviceinfo_manufacturer="LG"
deviceinfo_date=""
deviceinfo_year="1337"
deviceinfo_dtb=""
deviceinfo_modules_initfs=""
deviceinfo_external_storage="false"