Skip to content

Instantly share code, notes, and snippets.

@tai2
Created June 27, 2012 21:02
Show Gist options
  • Save tai2/3006828 to your computer and use it in GitHub Desktop.
Save tai2/3006828 to your computer and use it in GitHub Desktop.
Remove all Log.x function calls in a project for Android
#!/usr/bin/env python
import sys
import os
import re
def gather(path):
result = []
def f(arg, dirname, names):
for name in names:
filename = os.path.join(dirname, name)
if os.path.isfile(filename) and os.path.splitext(name)[1] == '.java':
result.append(filename)
os.path.walk(path, f, None)
return result
if __name__ == '__main__':
l = gather('./')
e = re.compile(r'^\s*Log\.([idevw]|wtf)\s*\(.+?\);\s*?\n', re.M | re.S)
for i, filename in enumerate(l):
file = open(filename, 'r')
text = file.read()
text = e.sub('', text)
file.close()
file = open(filename, 'w')
file.write(text)
file.close
print '\033[2K\033[30D%d of %d processed'%(i + 1, len(l)),
sys.stdout.flush()
print '\ndone'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment