-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.py
125 lines (117 loc) · 4.79 KB
/
extract.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# custom gapps extractor by wahyu6070
# 21.04 30-10-2021
#
import os
import zipfile
import tarfile
import subprocess
import shutil
import re
def UNTAR(INPUT, OUTPUT):
tar = tarfile.open(INPUT)
tar.extractall(OUTPUT)
tar.close()
def UNZIP(INPUT1, INPUT2):
with zipfile.ZipFile(INPUT1 , 'r') as zip_ref:
zip_ref.extractall(INPUT2)
INPUT = "input/"
TMP = "tmp/"
OUTPUT = "output/"
print(" ")
print(" Custom Gapps Extractor by wahyu6070")
print(" ")
for LIST_INPUT in os.listdir(INPUT):
if os.path.isfile(INPUT + LIST_INPUT):
if not os.path.exists(TMP + LIST_INPUT):
os.makedirs(TMP + LIST_INPUT)
else:
shutil.rmtree(TMP + LIST_INPUT)
os.makedirs(TMP + LIST_INPUT)
if not os.path.exists(OUTPUT + LIST_INPUT):
os.makedirs(OUTPUT + LIST_INPUT)
else:
shutil.rmtree(OUTPUT + LIST_INPUT)
os.makedirs(OUTPUT + LIST_INPUT)
if LIST_INPUT.startswith("open_gapps"):
print(" ")
print("- Opengapps Detected")
print("- Extracting : ", INPUT + LIST_INPUT)
UNZIP(INPUT + LIST_INPUT, TMP + LIST_INPUT)
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for file in files:
if file.endswith('.lz'):
LZ_IN = os.path.join(root, file)
LZ_OUT = os.path.join(root)
print("- Extracting •> ", LZ_IN)
# opengapps using lzip compression
subprocess.call(["tar", "-xf", LZ_IN, "-C", LZ_OUT])
os.remove(LZ_IN)
#moving files
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for FILES in dirs:
if FILES == 'nodpi':
input_mv = os.path.join(root, FILES)
out_mv = os.path.join(OUTPUT, LIST_INPUT, FILES)
shutil.copytree (input_mv, out_mv, dirs_exist_ok=True)
elif FILES == 'common':
input_mv = os.path.join(root, FILES)
out_mv = os.path.join(OUTPUT, LIST_INPUT, FILES)
shutil.copytree (input_mv, out_mv, dirs_exist_ok=True)
elif FILES == '480' or FILES == '213-240' or FILES == '560-640':
input_mv = os.path.join(root, FILES)
out_mv = os.path.join(OUTPUT, LIST_INPUT, FILES)
shutil.copytree (input_mv, out_mv, dirs_exist_ok=True)
elif FILES == '320' or FILES == '160' or FILES == '400-420-480':
input_mv = os.path.join(root, FILES)
out_mv = os.path.join(OUTPUT, LIST_INPUT, FILES)
shutil.copytree (input_mv, out_mv, dirs_exist_ok=True)
elif "LiteGapps" in LIST_INPUT:
print(" ")
print("- LiteGapps Detected")
print("- Extracting : ", INPUT + LIST_INPUT)
UNZIP(INPUT + LIST_INPUT, TMP + LIST_INPUT)
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for file in files:
if file.endswith('.tar.xz'):
print("- Extracting : ", file)
UNTAR(os.path.join(root, file),OUTPUT + LIST_INPUT)
elif "FlameGApps" in LIST_INPUT:
print(" ")
print("- FlameGApps Detected")
print("- Extracting : ", INPUT + LIST_INPUT)
UNZIP(INPUT + LIST_INPUT, TMP + LIST_INPUT)
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for file in files:
if file.endswith('.tar.xz'):
print("- Extracting : ", file)
UNTAR(os.path.join(root, file),OUTPUT + LIST_INPUT)
#
elif "BiTGApps" in LIST_INPUT:
print(" ")
print("- BiTGApps Detected")
print("- Extracting : ", INPUT + LIST_INPUT)
UNZIP(INPUT + LIST_INPUT, TMP + LIST_INPUT)
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for file in files:
if file.endswith('.tar.xz'):
print("- Extracting : ", file)
UNTAR(os.path.join(root, file), root)
os.remove(os.path.join(root, file))
shutil.copytree (TMP + LIST_INPUT, OUTPUT + LIST_INPUT , dirs_exist_ok=True)
elif "NikGapps" in LIST_INPUT:
print(" ")
print("- NikGapps Detected")
print("- Extracting : ", INPUT + LIST_INPUT)
UNZIP(INPUT + LIST_INPUT, TMP + LIST_INPUT)
for root, dirs, files in os.walk(TMP + LIST_INPUT):
for file in files:
if file.endswith('.tar.xz'):
print("- Extracting : ", file)
UNTAR(os.path.join(root, file), root)
os.remove(os.path.join(root, file))
shutil.copytree (TMP + LIST_INPUT, OUTPUT + LIST_INPUT , dirs_exist_ok=True)
else:
print("! Package not support : ", LIST_INPUT)
else:
print("! Is Not package file : ", INPUT + LIST_INPUT)
#shutil.rmtree(TMP)