-
Notifications
You must be signed in to change notification settings - Fork 7
/
patch_apply.py
executable file
·53 lines (48 loc) · 1.86 KB
/
patch_apply.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
#!/usr/bin/python3
import os
import shutil
import sys, getopt
def main(argv):
aosp_folder = ""
patch_folder = ""
try:
opts, args = getopt.getopt(argv, "ha:p:", ["aosp-folder=", "patch-folder="])
except getopt.GetoptError:
print('Usage: patch_apply.py -a <aosp_folder> -p <patch_folder>')
sys.exit(2)
if argv.__len__() < 2:
print('Please enter at least two arguments.\nUsage: patch_apply.py -a <aosp_folder> -p <patch_folder>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('Usage: patch_apply.py -a <aosp_folder> -p <patch_folder>')
sys.exit()
elif opt in ("-a", "--aosp-folder"):
aosp_folder = arg
print("AOSP root folder: " + arg)
elif opt in ("-p", "--patch-folder"):
patch_folder = arg
print("Patch folder: " + arg)
meta_file = os.path.join(patch_folder, "meta.txt")
if not os.path.exists(meta_file):
print("Meta file not exist!")
else:
with open(meta_file, 'r') as i:
for line in i.readlines():
action = line.strip().split("\t")[0]
f = line.strip().split("\t")[1]
dest = line.strip().split("\t")[2]
src = os.path.join(patch_folder, f)
dst = os.path.join(aosp_folder, dest)
if action == "ADD":
directory = dst.replace(dst.split("/")[-1], "")
if not os.path.exists(directory):
os.mkdir(directory)
print("Copying %s %s" % (src, dst))
shutil.copy(src, dst)
elif action == "PATCH":
cmd = "patch -u %s -i %s" % (dst, src)
print("Applying patch: " + cmd)
os.system(cmd)
if __name__ == "__main__":
main(sys.argv[1:])