|
Tips, beginner Python, the development environment is Sublime Text 2, directly Ctrl + B, and other circumstances not tuned. Should almost ^^
#################################################
# Environment: win + python 2.7
# Description: The first time you use the lint analysis will consume a few minutes, please be patient.
# Clean before use projects to ensure that projects under regenerate dex bin,
# For lint analysis. If you want to re-analyze the excess lint
# Resources, the need to delete (2) txt file records, (1) (3) (4) requires
# According to our actual project manually.
# If after clearing resources, engineering missing files and error (rarely
# Case) to try to recover the file by svn.
#################################################
import subprocess
import re
import os
import time
import thread
# (1) project location
projectPath = "D: \ / hao123 \ / code \ / client-android"
# (2) lint output txt file records
txt = "D: \ / hao123_unused_res.txt"
# (3) regular expression, under clear and layout drawable extra jpg / png / xml,
# And exclude sailor_ | wenku_ | zeus_ | bdsocialshare_ | floating_life_ | weather_info_icon_ | anthology_ beginning of the file
regex = re.compile (r "^ res \\ (drawable (-land) (- [xn] [mhlo] (dpi)) |??? layout) \\ ((sailor_ | wenku_ | zeus_ | bdsocialshare_ |?! floating_life_ | weather_info_icon_ | anthology _)) [0-9a-zA-Z _ \.] * \ (jpg |. png | xml) ", re.IGNORECASE)
# (4) lint.bat position
lint = "D: \ / sdk \ / tools \ /lint.bat"
isgotTxt = False
def timer (interval):
while not isgotTxt:
print 'Lint is analyzing:% s'% time.ctime ()
time.sleep (interval)
if not os.path.exists (txt):
thread.start_new_thread (timer, (5,))
cmd = lint + '--check "UnusedResources" "' + projectPath + '">' + txt
p = subprocess.Popen (cmd, shell = True, stdout = subprocess.PIPE, stdin = subprocess.PIPE, stderr = subprocess.PIPE)
p.wait ()
fobj = open (txt, 'r')
isgotTxt = True
i = 0
j = 0
for line in fobj:
#print str (i) + ":" + line
match = regex.match (line)
if match:
i = i + 1
filename = projectPath + "\ /" + match.group (). replace ( '\\', "\\ /")
try:
print filename
os.remove (filename)
j = j + 1
print "was deleted!"
except WindowsError:
print "is not exists"
pass
print "Total Unused Resources =" + str (i)
print "Total deleted Resources =" + str (j) |
|
|
|