diff options
-rwxr-xr-x | data/lineageos_wiki/find_lineageos_devices.py | 75 |
1 files 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 <https://www.gnu.org/licenses/>. +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]) |