Browse Source

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

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

20
utils/rules.py

@ -154,15 +154,17 @@ for filename in songfiles:
data = re.sub("''","{\\\\fg}", data) data = re.sub("''","{\\\\fg}", data)
else : else :
print "Warning: language is not defined for song : " + filename print "Warning: language is not defined for song : " + filename
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)
lines[index] = line
data = "\n".join(lines)
songfile.seek(0) songfile.seek(0)
songfile.write(data) songfile.write(data)
songfile.truncate() songfile.truncate()
for i, line in enumerate(fileinput.input(songfiles, inplace = 1)):
#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')

Loading…
Cancel
Save