ForgePatch/forge/clean_src.py
LexManos 91ab9d0e1b New script to fix decompile differences between windows and linux/osx.
Removed the MLProp special case, no longer needed as MLProp decompiles fine.
Updated patches to work on all systems.
Added warning and exit if the user does not say yes to the cleanup.
2012-03-12 16:55:59 -07:00

24 lines
No EOL
980 B
Python

import re, os, shutil, sys, fnmatch
if __name__ == '__main__':
print "Cleaning trailing zeros from source files"
trailing = re.compile(r'(?P<full>[0-9]+\.(?P<decimal>[0-9]+?)0)(?P<type>[Dd])')
for path, _, filelist in os.walk(sys.argv[1], followlinks=True):
for cur_file in fnmatch.filter(filelist, '*.java'):
src_file = os.path.normpath(os.path.join(path, cur_file))
tmp_file = src_file + '.tmp'
with open(src_file, 'r') as fh:
buf = fh.read()
def strip_zeros_match(match):
ret = match.group('full').rstrip('0')
if ret[-1] == '.':
ret += '0'
return ret
buf = trailing.sub(strip_zeros_match, buf) #Strip trailing zeroes: 1.0040D -> 1.004D
with open(tmp_file, 'w') as fh:
fh.write(buf)
shutil.move(tmp_file, src_file)