Created
June 30, 2018 11:28
-
-
Save ericzolf/708795d758acf589fc12bdcd46d06eed to your computer and use it in GitHub Desktop.
Python script to filter Android devices supported by LineageOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This crude script allows to filter Android devices supported by LineageOS | |
# You need to be in the directory where the YAML files are present, which | |
# are used to create the list seen at https://wiki.lineageos.org/devices/ | |
# You need first to edit the conditions used in the last 'if' statement to | |
# adapt this script (named $0 below) to your needs. Then usage could look | |
# like this: | |
# git clone https://github.com/LineageOS/lineage_wiki.git | |
# cd lineage_wiki/_data/devices | |
# (edit $0 and adapt the if-statement at the end of the script) | |
# $0 -> filtered list of devices appears | |
import os | |
import pprint | |
from yaml import load, dump | |
try: | |
from yaml import CLoader as Loader, CDumper as Dumper | |
except ImportError: | |
from yaml import Loader, Dumper | |
# generate a list of devices from all YAML files present in the current directory | |
devices = [] | |
for device_file in os.listdir("."): | |
if os.path.splitext(device_file)[1] == '.yml': | |
with open(device_file) as device_fd: | |
devices.append(load(device_fd, Loader=Loader)) | |
# create a pretty printer | |
pp = pprint.PrettyPrinter(indent=2) | |
def sort_devices(device): | |
""" | |
simple function to sort devices by vendor and name | |
""" | |
return device['vendor'] + device['name'] | |
# output each device that fits the chosen criteria | |
for device in sorted(devices, key=sort_devices): | |
if ( # adapt the following lines to your actual needs | |
15.1 in device['versions'] and | |
'phone' == device['type'] and | |
'arm64' == device['architecture'] and | |
None != device['sdcard'] | |
): | |
# output the device with a header and blank lines for readability | |
print("\n=== {} - {} ===\n".format(device['vendor'], device['name'])) | |
pp.pprint(device) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment