From 4570adde57161b7bc70b7f2a2ba0c0ce15e59a47 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Mon, 4 Mar 2024 23:10:19 +0100 Subject: lineageos_wiki: Handle YAML files with multiple SOCs. We want to make sure that all the code works with all the available devices to enable to modify the criteria and still have something that works. Unfortunately a very simple modification that makes the code print all devices like this one: if re.search("\.yml$", filepath): yaml_file = open(filepath, 'r') document = yaml.safe_load(yaml_file) - if still_supported(document) and interesting_for_replicant(document): + if True: store_infos(results, document) print_results(results) results in the following error: Traceback (most recent call last): File "[...]find_lineageos_devices.py", line 306, in find_devices(sys.argv[1]) File "[...]find_lineageos_devices.py", line 295, in find_devices store_infos(results, document) File "[...]find_lineageos_devices.py", line 263, in store_infos soc_data = parse_soc(soc) File "[...]find_lineageos_devices.py", line 129, in parse_soc match = re.search("^{0} (.*)".format(vendor), soc) File "/gnu/store/h1i5chzr8m4zmq1g318snb2327r1w6am-profile/lib/python3.10/re.py", line 200, in search return _compile(pattern, flags).search(string) TypeError: expected string or bytes-like object make: *** [Makefile:8: all] Error 1 This is because some devices YAML files have multiple SOCs. The fix is to treat each device <-> SOC combination as a single device. Signed-off-by: Denis 'GNUtoo' Carikli --- data/lineageos_wiki/find_lineageos_devices.py | 75 ++++++++++++++++++--------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/data/lineageos_wiki/find_lineageos_devices.py b/data/lineageos_wiki/find_lineageos_devices.py index 1e0509a..ee864dd 100755 --- a/data/lineageos_wiki/find_lineageos_devices.py +++ b/data/lineageos_wiki/find_lineageos_devices.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy import os import re import sys @@ -25,12 +26,31 @@ basedir = '_data' + os.sep + 'devices' results = {} last_lineageos_version = 17.1 -def still_supported(document): - if not last_lineageos_version in document['versions']: +def get_devices(document): + if type(document['soc']) == str: + return [document] + # find7_variant{1,2}.yml and Z00{A,B}.yml have 2 SOCs (and + # variants) so we need to treat them as 2 devices. + elif type(document['soc']) == list: + devices = [] + for soc in document['soc']: + device = copy.copy(document) + for key in ['codename', 'name']: + if key in document.keys(): + device[key] = document[key] + ' (' + soc + ')' + if 'soc' in document.keys(): + device['soc'] = soc + devices.append(device) + return devices + else: + assert(False) + +def still_supported(device): + if not last_lineageos_version in device['versions']: return False - if 'channels' in document.keys() and 'discontinued' in document['channels']: + if 'channels' in device.keys() and 'discontinued' in device['channels']: return False - if 'maintainers' in document.keys() and len(document['maintainers']) == 0: + if 'maintainers' in device.keys() and len(device['maintainers']) == 0: return False return True @@ -168,15 +188,15 @@ def battery_is_removable(battery): print("TODO: Handle batteries where removable is \"{}\": {}".format(removable, battery)) sys.exit(1) -def has_removable_battery(document): +def has_removable_battery(device): removable_battery = None - if 'battery' not in document: + if 'battery' not in device: # We don't know the policies reguarding incomplete data so the data # may either be incomplete or the device may not have a battery. print("TODO: Add support for devices lacking a battery") sys.exit(1) else: - battery = document.get('battery') + battery = device.get('battery') if type(battery) is not list: return battery_is_removable(battery) else: @@ -209,7 +229,7 @@ def has_removable_battery(document): print(" Add support for it in the parsing code") sys.exit(1) -def interesting_for_replicant(document): +def interesting_for_replicant(device): # For smartphones or tablets with a modem, since the modem is in # the same SOC, we would need to do some extensive review of the SOC # architecture to understand if the modem can be isolated with an IOMMU @@ -218,12 +238,12 @@ def interesting_for_replicant(document): # For devices without a modem, we would still need to make sure that the # sound card and the microphone is completely under the control of free # software and that there aren't too much proprietary libraries to replace - soc = parse_soc(document['soc']) + soc = parse_soc(device['soc']) if soc_has_modem(soc['vendor'], soc['product']) == True: return False - if device_has_shared_memory_between_modem_and_soc(document['vendor'], - document['name']): + if device_has_shared_memory_between_modem_and_soc(device['vendor'], + device['name']): return False # Non replaceable batteries causes too much issues for both users @@ -245,21 +265,21 @@ def interesting_for_replicant(document): # # So for now we aproximate non-removable batteries to non-replaceable # batteries until we find a way to deal with it. - if document['type'] != 'Set top box' and not has_removable_battery(document): + if device['type'] != 'Set top box' and not has_removable_battery(device): return False return True -def store_infos(results, document): +def store_infos(results, device): fields = ['vendor', 'name', 'type'] device_dict = {} for field in fields: - device_dict[field] = document[field] + device_dict[field] = device[field] - device_dict['removable_battery'] = has_removable_battery(document) + device_dict['removable_battery'] = has_removable_battery(device) - soc = document['soc'] + soc = device['soc'] soc_data = parse_soc(soc) soc_vendor = None soc_product = None @@ -285,23 +305,30 @@ def print_results(results): print(" * {0}: {1} ({2})".format( device['vendor'], device['name'], device['type'])) -def find_devices(path): +def find_devices(path, device_types): for filename in os.listdir(path + os.sep + basedir): filepath = path + os.sep + basedir + os.sep + filename if re.search("\.yml$", filepath): yaml_file = open(filepath, 'r') document = yaml.safe_load(yaml_file) - if still_supported(document) and interesting_for_replicant(document): - store_infos(results, document) + for device in get_devices(document): + if device_types == 'replicant': + if still_supported(device) and \ + interesting_for_replicant(device): + store_infos(results, device) + elif device_types == 'all': + store_infos(results, device) + print_results(results) def usage(argv0): progname = os.path.basename(argv0) - print("{} [path/to/lineage_wiki]".format(progname)) + print("{} [path/to/lineage_wiki] [all|replicant]".format(progname)) sys.exit(1) -if len(sys.argv) != 2: +if len(sys.argv) not in [2, 3]: usage(sys.argv[0]) - -find_devices(sys.argv[1]) - +elif len(sys.argv) == 2: + find_devices(sys.argv[1], 'replicant') +elif len(sys.argv) == 3: + find_devices(sys.argv[1], sys.argv[2]) -- cgit v1.2.3