Battery lists are now handled, None batteries too.

Signed-off-by: Denis 'GNUtoo' Carikli <[email protected]>
---
 research/find_lineageos_devices.py | 88 ++++++++++++++++++++++++++----
 1 file changed, 77 insertions(+), 11 deletions(-)

diff --git a/research/find_lineageos_devices.py 
b/research/find_lineageos_devices.py
index c32bcfc..427fe51 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:
-- 
2.24.1

_______________________________________________
Replicant mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to