-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_finder.py
More file actions
40 lines (34 loc) · 1.13 KB
/
project_finder.py
File metadata and controls
40 lines (34 loc) · 1.13 KB
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
import sys
import os.path
from lxml import etree
manifest_file = 'AndroidManifest.xml'
def find_projects(dr):
files = os.listdir(dr)
if manifest_file in files:
yield dr
else:
for f in files:
sub_dr = os.path.join(dr, f)
if os.path.isdir(sub_dr):
for project in find_projects(sub_dr):
yield project
def extract_string_resource(project_dir):
words = list()
strings_filepath = os.path.join(project_dir, 'res/values/strings.xml')
with open(strings_filepath, 'r') as f:
text = f.read()
tree = etree.fromstring(text)
for string_tag in tree.xpath('/resources/string'):
words.append(string_tag.attrib['name'])
print 'Word count:', len(words)
return words
if __name__ == '__main__':
total_words = list()
if len(sys.argv) == 2:
for project_path in find_projects(sys.argv[1]):
print 'Found project at:', project_path
try:
total_words += extract_string_resource(project_path)
except:
pass
print 'Totally: (', len(total_words), ') found'