-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathun_used.py
41 lines (32 loc) · 979 Bytes
/
un_used.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
# coding=utf-8
import glob
import os
import re
path = 'ios'
ignores = {r'image_\d+'}
images = glob.glob('ios/images.xcassets/*/*.imageset')
def find_un_used():
img_names = [os.path.basename(pic)[:-9] for pic in images]
unused_imgs = []
for i in range(0, len(images)):
pic_name = img_names[i]
if is_ignore(pic_name):
continue
command = 'ag "%s" %s' % (pic_name, path)
result = os.popen(command).read()
if result == '':
unused_imgs.append(images[i])
print 'remove %s' % (images[i])
os.system('rm -rf %s' % (images[i]))
text_path = 'unused.txt'
tex = '\n'.join(sorted(unused_imgs))
os.system('echo "%s" > %s' % (tex, text_path))
print 'unuse res:%d' % (len(unused_imgs))
print 'Done!'
def is_ignore(str):
for ignore in ignores:
if re.match(ignore, str):
return True
return False
if __name__ == '__main__':
find_un_used()