Skip to content

Commit bb231c1

Browse files
committed
WIP - Add small script to check if lineageos image works for device
1 parent 1815df9 commit bb231c1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

scripts/check-image-for-device.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Script to check if a given lineageOS image works for a connected device."""
2+
from os import device_encoding
3+
from typing import Dict
4+
from subprocess import check_output, STDOUT
5+
6+
7+
def get_device_info() -> Dict[str, str]:
8+
"""Read the device properties with adb."""
9+
# read properties
10+
device_properties = check_output(
11+
['adb', 'shell', 'getprop'], stderr=STDOUT).decode()
12+
# clean and structure the properties into dict
13+
properties_dict = dict([
14+
prop.replace("[", "").replace("]", "").split(":", 1)
15+
for prop in device_properties.split('\n') if len(prop) > 2
16+
])
17+
# filter down to some relevant properties used for identifying the device
18+
relevant_keys = ("ro.product.manufacturer", "ro.product.model", "ro.product.name")
19+
return {key: properties_dict[key].strip() for key in relevant_keys}
20+
21+
22+
def image_works(image_path: str, device_code: str) -> bool:
23+
"""Determine if the image works or not."""
24+
raw_text = check_output(['cat', f'{image_path}'], stderr=STDOUT).decode(encoding='latin')
25+
return device_code in raw_text
26+
27+
28+
if __name__ == "__main__":
29+
device_info = get_device_info()
30+
print(device_info)
31+
32+
#image_path = "images/samsung-galaxy-a3/lineage-16.0-20190908-UNOFFICIAL-a3y17lte.zip"
33+
image_path = "images/samsung-galaxy-a3/lineage-17.1-20200830-UNOFFICIAL-a3y17lte.zip"
34+
works = image_works(image_path, device_code=device_info['ro.product.name'])
35+
if works:
36+
print("This image works for your device!")
37+
else:
38+
print("This image will not work for your device...")

0 commit comments

Comments
 (0)