Last active
April 3, 2022 11:58
-
-
Save diresi/3fa596331eaec1e1896b15880526fbf7 to your computer and use it in GitHub Desktop.
sort lineage devices by some attribute, default is to sort by height
This file contains 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
# sort lineage devices by some attribute, default is to sort by height: | |
# | |
# - download lineage_wiki, e.g. by cloning it: | |
# git clone https://github.com/LineageOS/lineage_wiki.git | |
# | |
# - change into the root directory, e.g: | |
# cd lineage_wiki | |
# | |
# - run this script: | |
# python devs.py | |
# | |
# feel free to modify the 'key' at the bottom of this script | |
import operator | |
import os | |
import yaml | |
def _iter_devices(basedir="_data/devices"): | |
for bd, d, fns in os.walk("_data/devices"): | |
for fn in fns: | |
try: | |
fn = os.path.join(bd, fn) | |
yield yaml.safe_load(open(fn)) | |
except Exception: | |
pass | |
def _explode(it, key): | |
for o in it: | |
v = o[key] | |
if isinstance(v, list): | |
for d in v: | |
n, i = next(iter(d.items())) | |
oo = o.copy() | |
oo["codename"] = f"{o['codename']} + {n}" | |
oo[key] = i | |
yield oo | |
else: | |
yield o | |
def _collect(): | |
for x in _iter_devices(): | |
dim = x.get("dimensions") | |
if dim in ('', None, 'None'): | |
continue | |
if isinstance(dim, list): | |
#print("skip", x) | |
continue | |
h = dim["height"] | |
h = h.split(" ", 1)[0] | |
h = float(h) | |
yield h, x | |
def _sort(): | |
it = _collect() | |
return sorted(it, key=lambda x: x[0]) | |
if __name__ == "__main__": | |
for h, o in _sort(): | |
print(f"{o['codename']:<20} {h:<20} {o['current_branch']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment