""" Compile the same file with LilyPond, writing standard error to log0.txt and log1.txt alternatively. Compares all lines starting with the `@' symbol. If lines diverge, stop the script and report the offending line. """ import subprocess import sys LILYPOND_EXECUTABLE = 'Lilypond' FILE_TO_COMPILE = 'foo.ly' #FILE_TO_COMPILE = 'bar.ly' MAX_RUNS = 100 for i in range (MAX_RUNS) : subprocess.call (LILYPOND_EXECUTABLE+' '+FILE_TO_COMPILE+' 2> log'+str(i%2)+'.txt', shell=True) if i > 1 : print "ON COMPARISON", i - 1 f0 = file('log'+str(i%2)+'.txt','r') c0 = f0.read () f0.close () f1 = file('log'+str((i+1)%2)+'.txt','r') c1 = f1.read () f1.close () c0 = c0.split ('\n') c1 = c1.split ('\n') c0x = 0 c1x = 0 while (c0x < len(c0)) & (c1x < len(c1)) : try : while (c0[c0x][0] != '@') : c0x += 1 except IndexError : pass try : while (c1[c1x][0] != '@') : c1x += 1 except IndexError : pass if (c0x >= len(c0)) | (c1x >= len(c1)) : break # stop the script and report the offending line if c0[c0x] != c1[c1x] : print "DIVERGES HERE", c0x, c1x, c0[c0x], c1[c1x], sys.exit (1) c0x += 1 c1x += 1