2022-01-02 21:38:21 +00:00
|
|
|
# Copyright 2022 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-05-26 20:08:45 +00:00
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import pmb.parse
|
|
|
|
|
|
|
|
|
2020-02-26 11:13:26 +00:00
|
|
|
def find_path(args, codename, file=''):
|
|
|
|
"""
|
|
|
|
Find path to device APKBUILD under `device/*/device-`.
|
|
|
|
:param codename: device codename
|
|
|
|
:param file: file to look for (e.g. APKBUILD or deviceinfo), may be empty
|
|
|
|
:returns: path to APKBUILD
|
|
|
|
"""
|
|
|
|
g = glob.glob(args.aports + "/device/*/device-" + codename + '/' + file)
|
|
|
|
if not g:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if len(g) != 1:
|
|
|
|
raise RuntimeError(codename + " found multiple times in the device"
|
|
|
|
" subdirectory of pmaports")
|
|
|
|
|
|
|
|
return g[0]
|
|
|
|
|
|
|
|
|
2021-01-30 12:21:12 +00:00
|
|
|
def list_codenames(args, vendor=None, unmaintained=True):
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
Get all devices, for which aports are available
|
2019-10-13 14:09:32 +00:00
|
|
|
:param vendor: vendor name to choose devices from, or None for all vendors
|
2021-01-30 12:21:12 +00:00
|
|
|
:param unmaintained: include unmaintained devices
|
2017-05-26 20:08:45 +00:00
|
|
|
:returns: ["first-device", "second-device", ...]
|
|
|
|
"""
|
|
|
|
ret = []
|
2020-02-26 11:13:26 +00:00
|
|
|
for path in glob.glob(args.aports + "/device/*/device-*"):
|
2021-01-30 12:21:12 +00:00
|
|
|
if not unmaintained and '/unmaintained/' in path:
|
|
|
|
continue
|
2017-05-26 20:08:45 +00:00
|
|
|
device = os.path.basename(path).split("-", 1)[1]
|
2019-10-13 14:09:32 +00:00
|
|
|
if (vendor is None) or device.startswith(vendor + '-'):
|
|
|
|
ret.append(device)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def list_vendors(args):
|
|
|
|
"""
|
|
|
|
Get all device vendors, for which aports are available
|
|
|
|
:returns: {"vendor1", "vendor2", ...}
|
|
|
|
"""
|
|
|
|
ret = set()
|
2020-02-26 11:13:26 +00:00
|
|
|
for path in glob.glob(args.aports + "/device/*/device-*"):
|
2019-10-13 14:09:32 +00:00
|
|
|
vendor = os.path.basename(path).split("-", 2)[1]
|
|
|
|
ret.add(vendor)
|
2017-05-26 20:08:45 +00:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def list_apkbuilds(args):
|
|
|
|
"""
|
|
|
|
:returns: { "first-device": {"pkgname": ..., "pkgver": ...}, ... }
|
|
|
|
"""
|
|
|
|
ret = {}
|
2019-01-09 07:07:27 +00:00
|
|
|
for device in list_codenames(args):
|
2021-05-19 18:36:24 +00:00
|
|
|
apkbuild_path = f"{args.aports}/device/*/device-{device}/APKBUILD"
|
2021-11-09 11:52:10 +00:00
|
|
|
ret[device] = pmb.parse.apkbuild(apkbuild_path)
|
2017-05-26 20:08:45 +00:00
|
|
|
return ret
|
2019-01-09 00:48:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def list_deviceinfos(args):
|
|
|
|
"""
|
|
|
|
:returns: { "first-device": {"name": ..., "screen_width": ...}, ... }
|
|
|
|
"""
|
|
|
|
ret = {}
|
2019-01-09 07:07:27 +00:00
|
|
|
for device in list_codenames(args):
|
2019-01-09 00:48:25 +00:00
|
|
|
ret[device] = pmb.parse.deviceinfo(args, device)
|
|
|
|
return ret
|