forked from meganz/MEGAchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove-from-DEPS.py
50 lines (41 loc) · 1.52 KB
/
remove-from-DEPS.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
#!/usr/bin/python2
# This script edits a gclient DEPS file and removed the specified dependencies and hooks.
import re
import os
import sys
if len(sys.argv) < 2:
print("Too few argments")
print("Usage: <DEPS file> <list-of-things-to-remove>")
exit(1)
deplistfile=open(sys.argv[2])
deplist=deplistfile.readlines();
depfile = open(sys.argv[1], "r+b");
data=depfile.read();
for dep in deplist:
dep = dep.strip();
if not dep:
continue
type = dep[0]
if type == '#':
continue
if dep[1] != ' ':
raise Exception("Second char on a non-comment line must be space")
dep=dep[1:].strip()
prevlen = len(data)
if type == 'd':
rxdep=dep.replace('/','\/')
rx="^\s*'src\/"+rxdep+"':[^,]+,.*\n"
data=re.sub(rx, "", data, 0, re.M)
print("Remove dependency '%s': %s" % (dep, ("success" if len(data) != prevlen else "\033[1;31mFAIL\033[0;0m")))
elif type == 'h':
data = re.sub("{(\s*#.*$)*\n\s*'name':\s*'"+dep+"',\s*\n[^}]+},", "", data, 0, re.M)
print("Remove hook '%s': %s" % (dep, ("success" if len(data) != prevlen else "\033[1;31mFAIL\033[0;0m")))
elif type == 'm': #hook without a name, identify plain string match
data = re.sub(dep, "", data, 0, re.M);
print("Remove hook by match '%s': %s" % (dep, ("success" if len(data) != prevlen else "\033[1;31mFAIL\033[0;0m")))
else:
print("\033[1;31mUknown entry type '%s'\033[0;0m" % (type))
depfile.seek(0)
depfile.write(data)
depfile.truncate()
depfile.close()