Last active
May 30, 2017 14:28
-
-
Save NickJian/aeebdec2d5709deec34142690409bcb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Due to bugs in android resouce remover, the unused layout files is not removed | |
import xml.etree.ElementTree as ET | |
import os | |
import fnmatch | |
def find(pattern, path): | |
result = [] | |
for root, dirs, files in os.walk(path): | |
for name in files: | |
if fnmatch.fnmatch(name, pattern): | |
result.append(os.path.join(root, name)) | |
return result | |
print 'find lint xml' | |
lintfile = find('lint-results*.xml', './') | |
print '\nstart to remove what android res remover did not clean out...' | |
tree = ET.ElementTree(file=lintfile[0]) | |
for elem in tree.iterfind('issue[@id="UnusedResources"]'): | |
for lac in elem.findall('location'): | |
path = lac.get('file') | |
if '/res/layout/' in path or '/res/drawable' in path or '/res/menu' in path: | |
try: | |
os.remove(path) | |
print 'remove file: ', path | |
except OSError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment