-
Notifications
You must be signed in to change notification settings - Fork 6
/
listdrawable.py
58 lines (47 loc) · 1.52 KB
/
listdrawable.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
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import os
import sys
class ListDrawable(object):
blacklist = ['build', 'libs', 'androidTest', 'assets', 'test', 'gradle', '.gradle', '.idea', '.git']
def __init__(self, searchDir):
super(ListDrawable, self).__init__()
self.searchDir = os.path.abspath(searchDir)
print('init ListDrawable searchDir: %s' % self.searchDir)
def search(self):
drawableDirs = list()
baseDir = self.searchDir
self.__find_drawables(drawableDirs, baseDir)
return drawableDirs
def __find_drawables(self, listResult, currentPath):
if not os.path.isdir(currentPath):
return
if self.__is_in_blacklist(currentPath):
return
if self.__is_drawable_dir(currentPath):
listResult.append(currentPath)
return
for d in os.listdir(currentPath):
tmpPath = os.path.join(currentPath, d)
if not os.path.isdir(tmpPath):
continue
self.__find_drawables(listResult, tmpPath)
def __is_drawable_dir(self, folder):
head, tail = os.path.split(folder)
return (tail.startswith('drawable') or tail.startswith('mipmap'))
def __is_in_blacklist(self, folder):
head, tail = os.path.split(folder)
inBlacklist = False
try:
index = ListDrawable.blacklist.index(tail)
inBlacklist = index >= 0
except Exception as e:
inBlacklist = False
return inBlacklist
if __name__ == '__main__':
searchDir = '.'
if len(sys.argv) == 2:
searchDir = sys.argv[1]
print('from input searchDir:', searchDir)
dawables = ListDrawable(searchDir).search()
print('searched images======>\n', dawables)