-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-apks.py
executable file
·47 lines (37 loc) · 1.13 KB
/
import-apks.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
#!/usr/bin/env python3
import os
import re
import shlex
import shutil
import subprocess
import sys
for i in range(1, len(sys.argv)):
path = sys.argv[i]
print("\nimporting " + path)
badging = subprocess.check_output(["aapt2", "dump", "badging", path])
lines = badging.split(b"\n")
version = None
pkg_name = None
abi = None
is_split = False
for kv in shlex.split(lines[0].decode()):
if kv.startswith("versionCode"):
version = kv.split("=")[1]
elif kv.startswith("name"):
pkg_name = kv.split("=")[1]
elif kv.startswith("split"):
is_split = True
assert version != None
assert pkg_name != None
dest_dir = "apps/packages/" + pkg_name + "/" + version
if not os.path.isdir(dest_dir):
os.makedirs(dest_dir)
with open(dest_dir + "/props.toml", "w") as f:
f.write("channel = \"alpha\"\n")
if is_split:
shutil.copy(path, dest_dir)
print("copied to " + dest_dir)
else:
dest_path = dest_dir + "/base.apk"
shutil.copyfile(path, dest_path)
print("copied to " + dest_path)