WARNING: This script is very rough-and-ready. Backup your class files before letting this loose on them!!!
Download from here...
http://dynamicflash.com/misc/removeimports.py
Use it like this...
mtasc [options etc] 2>&1 | removeimports.py
This redirects stderr to stdout (2>&1) and then pipes the entire lot to the removeimports.py script.
Cheers,
Steve Webster
The code is reproduced below, should the link above ever die.
#!/usr/bin/python
import sys, os, re
p = re.compile('^(.*):([0-9]+): characters (?:[0-9]+)-(?:[0-9]+) : Warning import not used$', re.L)
files = {}
for line in sys.stdin:
m = p.match(line)
if (m):
filename = m.group(1)
lineNumber = int(m.group(2))
if files.has_key(filename) == False:
files[filename] = []
files[filename].append(lineNumber)
for filename, lineNumbers in files.iteritems():
lineNumbers.sort()
lineNumbers.reverse()
print filename
lines = open(filename, 'r').readlines()
for lineNumber in lineNumbers:
print " - " + lines[lineNumber - 1]
del lines[lineNumber - 1]
open(filename, 'w').writelines(lines)
mtasc_remove_imports.txt · Last modified: 2005/08/02 10:00