This repository was archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
55 lines (43 loc) · 1.24 KB
/
script.py
File metadata and controls
55 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import subprocess
def get_data_partition(_sn):
"""Get data partiton.
Args:
_sn (str): Serial number.
Returns:
str: Partition path.
"""
command = 'adb -s {serial_number} shell mount' \
.format(serial_number=_sn)
p = subprocess.Popen(
command.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
while True:
sn_line = p.stdout.readline()
if not sn_line:
break
if '/data' in sn_line:
return sn_line.split()[0]
def erase_partition(partition, _sn):
"""Get data partiton.
Args:
_sn (str): Serial number.
Returns:
str: Partition path.
"""
command_first = 'adb -s {serial_number}' \
.format(serial_number=_sn)
command_end = 'shell dd if=/dev/zero of={partition}' \
.format(partition=partition)
p = subprocess.Popen(
command_first.split() + command_end.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
if __name__ == '__main__':
serial_number = "21f4c3ce"
partition = get_data_partition(serial_number)
erased = erase_partition(partition, serial_number)