From a366c26466209675629e0ec8940623cfd9661ab7 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Sun, 22 Dec 2019 18:16:55 +0100 Subject: Add script to print devices with removable batteries Signed-off-by: Denis 'GNUtoo' Carikli --- .gitmodules | 3 + .../Replicant_sustainability.tex | 24 ++++ ...d_lineageos_devices_with_removable_batteries.py | 133 +++++++++++++++++++++ external_resources/lineage_wiki | 1 + 4 files changed, 161 insertions(+) create mode 100755 36c3/Replicant_sustainability/scripts/find_lineageos_devices_with_removable_batteries.py create mode 160000 external_resources/lineage_wiki diff --git a/.gitmodules b/.gitmodules index 1986570..8120fbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Replicant_contributors_meeting_27_28_July_2019_Paris_France/bootloaders/replicant_website"] path = external_resources/replicant_website url = https://git.replicant.us/replicant/website.git +[submodule "external_resources/lineage_wiki"] + path = external_resources/lineage_wiki + url = git://github.com/LineageOS/lineage_wiki.git diff --git a/36c3/Replicant_sustainability/Replicant_sustainability.tex b/36c3/Replicant_sustainability/Replicant_sustainability.tex index 91d1070..ae5a3cb 100644 --- a/36c3/Replicant_sustainability/Replicant_sustainability.tex +++ b/36c3/Replicant_sustainability/Replicant_sustainability.tex @@ -143,6 +143,30 @@ \end{itemize} \end{frame} +\section{The dylema} + +\begin{frame} + \center{From a purely sustainable perspective:} + \begin{xtabular}{ll} + Big brand old devices & Big brand new devices \\ + Removable battery & Battery too difficult to replace \\ + Device specific kernel & Device specific modules \\ + Changing HAL API & HAL API being versioned \\ + \end{xtabular} +\end{frame} + +\begin{frame} + \center{If we look at LineageOS:} + \begin{itemize} + \item SOCs, WiFi chips, smartphones and tablets + \item Write the code that work as fast as possible + \item Support as many hardware features as possible + \item $\rightarrow$ Varying code quality + \item $\rightarrow$ Example: One driver rewritten 3 times %% TODO: reference + \item Breaking Kernel API and ABI + \end{itemize} +\end{frame} + %% \begin{frame} %% Licenses: %% \begin{itemize} diff --git a/36c3/Replicant_sustainability/scripts/find_lineageos_devices_with_removable_batteries.py b/36c3/Replicant_sustainability/scripts/find_lineageos_devices_with_removable_batteries.py new file mode 100755 index 0000000..d94499b --- /dev/null +++ b/36c3/Replicant_sustainability/scripts/find_lineageos_devices_with_removable_batteries.py @@ -0,0 +1,133 @@ +#!/bin/env python +# Program to find devices to support in LineageOS +# Copyright (C) 2019 Denis 'GNUtoo' Carikli +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +import re +import sys +import yaml + +basedir = '_data' + os.sep + 'devices' +results = {} +last_lineageos_version = 16.0 + +def still_supported(document): + if not last_lineageos_version in document['versions']: + return False + if 'discontinued' in document['channels']: + return False + + return True + +def interesting_for_sustainability(document): + # Non removable batteries are not sustainable + removable_battery = None + battery = document.get('battery', {}) + if type(battery) is not list: + removable_battery = battery.get('removable', None) + if removable_battery == None: + return False + elif removable_battery == False: + return False + else: + for battery_version in battery: + nr_removable = 0 + nr_not_removable = 0 + removable = battery_version.get('removable', None) + if removable == None: + return False + elif 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:" + battery) + print(" Add support for it in the parsing code") + sys.exit(1) + return True + return True + +def store_infos(results, document): + fields = ['vendor', 'name', 'type'] + + device_dict = {} + for field in fields: + device_dict[field] = document[field] + + removable_battery = None + battery = document.get('battery', {}) + if type(battery) is not list: + removable_battery = battery.get('removable', None) + else: + print(battery) + if removable_battery == None: + device_dict['removable_battery'] = 'Unknown' + else: + device_dict['removable_battery'] = removable_battery + + soc = document['soc'] + if not soc in results: + results[soc] = [] + + results[soc].append(device_dict) + +def print_results(results): + socs = list(results.keys()) + socs.sort() + + formfactors = [] + for soc in socs: + for device in results[soc]: + if device['type'] not in formfactors: + formfactors.append(device['type']) + + if len(formfactors) == 1: + print("{0}:".format(formfactors[0][0].capitalize() + formfactors[0][1:] + 's')) + for soc in socs: + print ("- {0}:".format(soc)) + for device in results[soc]: + print (" * {0}: {1}".format(device['vendor'], device['name'])) + else: + for soc in socs: + print ("{0}:".format(soc)) + for device in results[soc]: + print ("- {0}: {1} ({2})".format(device['vendor'], device['name'], device['type'])) + +def find_devices(path): + 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.load(yaml_file) + if still_supported(document) and interesting_for_sustainability(document): + store_infos(results, document) + print_results(results) + +def usage(argv0): + progname = os.path.basename(argv0) + print("{} [path/to/lineage_wiki]".format(progname)) + sys.exit(1) + +if len(sys.argv) != 2: + usage(sys.argv[0]) + +find_devices(sys.argv[1]) + diff --git a/external_resources/lineage_wiki b/external_resources/lineage_wiki new file mode 160000 index 0000000..065f498 --- /dev/null +++ b/external_resources/lineage_wiki @@ -0,0 +1 @@ +Subproject commit 065f4989b7aceafdcad091ec6e76770989ff21f6 -- cgit v1.2.3