-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathscancode.py
52 lines (43 loc) · 1.15 KB
/
scancode.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2014 Arming lee <[email protected]>
#
# Distributed under terms of the MIT license.
"""
scan qzone source code to get all strings defined, like @"xxx".
"""
import os
import re
from removecomment import remove_comments
source_dir = "/Users/sngTest/Documents/EclipseWorkSpace/code/test/src"
def iter_directory(path):
files = []
for f in os.listdir(path):
p = os.path.join(path, f)
if os.path.isfile(p):
files.append(p)
elif os.path.isdir(p):
files += iter_directory(p)
return files
pattern = re.compile("@\"([^\"]*)\"", re.VERBOSE|re.MULTILINE)
def scanfile(filepath):
strings = set()
with open(filepath) as f:
text = f.read()
clean_text = remove_comments(text)
for m in pattern.finditer(clean_text):
strings.add(m(1))
return strings
def main():
files = iter_directory(source_dir)
strs = set()
for f in files:
strs |= scanfile(f)
f = open("strings_in_qzone", "w")
for s in strs:
print s>>f
f.close()
if __name__ == "__main__":
main()