Browse Source

Utils: improve performance by opening files only once (thanks Guibou!)

remotes/origin/cmake
Romain Goffe 13 years ago
parent
commit
c11b1681c4
  1. 16
      utils/rules.py

16
utils/rules.py

@ -155,14 +155,16 @@ for filename in songfiles:
else :
print "Warning: language is not defined for song : " + filename
songfile.seek(0)
songfile.write(data)
songfile.truncate()
for i, line in enumerate(fileinput.input(songfiles, inplace = 1)):
lines = data.split('\n')
for index, line in enumerate(lines):
#remove trailing spaces and punctuation
line = line.rstrip().rstrip(',.;').rstrip()
#remove multi-spaces within lines
line = re.sub("(?P<last_char>\S)\s{2,}","\g<last_char> ", line)
#write correct line
sys.stdout.write(line+'\n')
lines[index] = line
data = "\n".join(lines)
songfile.seek(0)
songfile.write(data)
songfile.truncate()

Loading…
Cancel
Save