diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-12-22 18:45:51 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-12-23 16:55:10 +0100 |
commit | e71b1668529b2de49fdb77559ead42e153b55829 (patch) | |
tree | 22bb8405c47f389750a8eaf5b8607ca506603c6a | |
parent | 2dc3389718594238e71f8e8f3271cf0008522be4 (diff) | |
download | vendor_replicant-scripts-e71b1668529b2de49fdb77559ead42e153b55829.tar.gz vendor_replicant-scripts-e71b1668529b2de49fdb77559ead42e153b55829.tar.bz2 vendor_replicant-scripts-e71b1668529b2de49fdb77559ead42e153b55829.zip |
find_lineageos_devices.py: improve battery parsing
Battery lists are now handled, None batteries too.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-x | research/find_lineageos_devices.py | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/research/find_lineageos_devices.py b/research/find_lineageos_devices.py index 4a4c3d3..2970b62 100755 --- a/research/find_lineageos_devices.py +++ b/research/find_lineageos_devices.py @@ -32,6 +32,65 @@ def still_supported(document): return True +def battery_is_removable(battery): + # Example: Set top box + if battery == "None" or battery == None: + return None + + if 'removable' not in battery: + print("TODO: Handle batteries where removable is absent: {}".format(battery)) + sys.exit(1) + + removable_battery = battery.get('removable') + if removable_battery == True: + return True + elif removable_battery == False: + return False + else: + print("TODO: Handle batteries where removable is \"{}\": {}".format(removable, battery)) + sys.exit(1) + +def has_removable_battery(document): + removable_battery = None + if 'battery' not in document: + # 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') + if type(battery) is not list: + return battery_is_removable(battery) + else: + for battery_version in battery: + if battery_version == None: + continue + + if len(battery_version.keys()) != 1: + print("TODO: Add support for battery versions with multiple keys: {}".format(battery_version)) + sys.exit(1) + + nr_removable = 0 + nr_not_removable = 0 + + (battery_name, battery_data), = battery_version.items() + + removable = battery_is_removable(battery_data) + if removable == True: + nr_removable += 1 + elif removable == False: + nr_not_removable += 1 + + if nr_removable == 0 and nr_not_removable > 0: + return False + elif nr_not_removable == 0 and nr_removable > 0: + return True + else: + print("TODO: The data has removable and non-removable batteries" + "versions for the same device: {}".format(battery)) + print(" Add support for it in the parsing code") + sys.exit(1) + def interesting_for_replicant(document): # 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 @@ -44,15 +103,26 @@ def interesting_for_replicant(document): if re.search("Qualcomm", document['soc']): return False - # Non removable batteries causes too much issues for both users + # Non replaceable batteries causes too much issues for both users # and developers as once you buy a device second hand, the battery # doesn't last as much as when the device is new. On some devices, - # replicing non-replacable batteries can be very difficult and damage + # replicing non-removable batteries can be very difficult and damage # the device along the way - removable_battery = document.get('battery', {}).get('removable', None) - if removable_battery == None: - pass # Unknown - elif removable_battery == False: + # + # There are some devices where the battery is not removable but + # since the device can be easily opened, and that the battery has + # a connector, it might be possible for an experienced user or + # developer, or a repair shop, or a repair café to open the device + # and replace the battery. + # + # However it would take more research to understand if compatible + # batteries replacement can easily be found. The LineageOS wiki also + # doesn't have a way to distinguish between devices that can be easily + # opened and the ones that aren't. + # + # 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): return False return True @@ -64,11 +134,7 @@ def store_infos(results, document): for field in fields: device_dict[field] = document[field] - removable_battery = document.get('battery', {}).get('removable', None) - if removable_battery == None: - device_dict['removable_battery'] = 'Unknown' - else: - device_dict['removable_battery'] = removable_battery + device_dict['removable_battery'] = has_removable_battery(document) soc = document['soc'] if not soc in results: |