#!/usr/bin/python import re, sys, os if len(sys.argv) < 2: print "No filename given" sys.exit(1) fInName=sys.argv[1] fOutName=re.compile("\.ly$").sub(".conv.ly",fInName) print fOutName reStaff=re.compile("Staff") rePianoStart=re.compile("\\context PianoStaff = \".*?\"") reVoiceStart=re.compile("\\context Voice = \".*?\"") try: print "Opening file: "+fInName fOut=open(fOutName,'w') print "Converting file..." for line in open(fInName): line=reStaff.sub("PianoStaff",line) mo=rePianoStart.search(line) if mo: end=mo.end() line=line[:end]+" \\autochange "+line[end+1:] mo=reVoiceStart.search(line) if mo: end=mo.end() line=line[:end]+" \\autochange "+line[end+1:] fOut.write(line) fOut.close() print "Running lilypond on converted file: "+fOutName+" ..." lilyOutName=re.compile("\.ly$").sub("",fOutName) os.system("lilypond -o \""+ lilyOutName+"\" \""+fOutName+"\"") # comment out the next 2 lines if you want the intermediate files to be left in place. print "Cleaning up..." os.system("rm "+lilyOutName+".ly "+lilyOutName+".ps") print "\nDone." except IOError,err: import errno if err.errno != errno.ENOENT: raise else: print "Can't open file: " + fInName sys.exit(2)