3 # convert-ly.py -- convertor for lilypond versions
5 # source file of the GNU LilyPond music typesetter
10 # use -f and -t for -s output
16 program_name = 'convert-ly'
17 version = '@TOPLEVEL_VERSION@'
27 # Did we ever have \mudela-version? I doubt it.
28 # lilypond_version_re_str = '\\\\version *\"(.*)\"'
29 lilypond_version_re_str = '\\\\(mudela-)?version *\"(.*)\"'
30 lilypond_version_re = re.compile (lilypond_version_re_str)
33 return '%s (GNU LilyPond) %s' %(program_name, version);
36 sys.stderr.write (program_id () + '\n')
40 r"""Usage: %s [OPTION]... [FILE]...
41 Try to convert to newer lilypond-versions. The version number of the
42 input is guessed by default from \version directive
45 -a, --assume-old apply all conversions to unversioned files
46 -h, --help print this help
47 -e, --edit in place edit
48 -f, --from=VERSION start from version
49 -s, --show-rules print all rules.
50 -t, --to=VERSION target version
51 --version print program version
53 Report bugs to bugs-gnu-music@gnu.org
62 sys.stdout.write (r"""%s
64 This is free software. It is covered by the GNU General Public
65 License, and you are welcome to change it and/or distribute copies of
66 it under certain conditions. invoke as `%s --warranty' for more
69 """ % (program_id() , program_name))
78 print 'can\'t open file: ' + f + '\n'
82 print 'gulped empty file: ' + f + '\n'
87 return tuple (map (string.atoi, string.split (s,'.')))
90 return string.join (map (lambda x: '%s' % x, list (t)), '.')
92 def version_cmp (t1, t2):
98 def guess_lilypond_version (filename):
99 s = gulp_file (filename)
100 m = lilypond_version_re.search (s)
106 class FatalConversionError:
111 def show_rules (file):
112 for x in conversions:
113 file.write ('%s: %s\n' % (tup_to_str (x[0]), x[2]))
115 ############################
119 if re.search ('\\\\multi', str):
120 sys.stderr.write ('\nNot smart enough to convert \\multi')
123 conversions.append (((0,1,9), conv, '\\header { key = concat + with + operator }'))
125 if 1: # need new a namespace
127 if re.search ('\\\\octave', str):
128 sys.stderr.write ('\nNot smart enough to convert \\octave')
129 # raise FatalConversionError()
133 conversions.append ((
134 ((0,1,19), conv, 'deprecated \\octave; can\'t convert automatically')))
137 if 1: # need new a namespace
139 str = re.sub ('\\\\textstyle([^;]+);',
140 '\\\\property Lyrics . textstyle = \\1', str)
141 # harmful to current .lys
142 # str = re.sub ('\\\\key([^;]+);', '\\\\accidentals \\1;', str)
146 conversions.append ((
147 ((0,1,20), conv, 'deprecated \\textstyle, new \key syntax')))
152 str = re.sub ('\\\\musical_pitch', '\\\\musicalpitch',str)
153 str = re.sub ('\\\\meter', '\\\\time',str)
157 conversions.append ((
158 ((0,1,21), conv, '\\musical_pitch -> \\musicalpitch, '+
159 '\\meter -> \\time')))
165 conversions.append ((
166 ((1,0,0), conv, '0.1.21 -> 1.0.0 ')))
171 str = re.sub ('\\\\accidentals', '\\\\keysignature',str)
172 str = re.sub ('specialaccidentals *= *1', 'keyoctaviation = 0',str)
173 str = re.sub ('specialaccidentals *= *0', 'keyoctaviation = 1',str)
177 conversions.append ((
178 ((1,0,1), conv, '\\accidentals -> \\keysignature, ' +
179 'specialaccidentals -> keyoctaviation')))
183 if re.search ('\\\\header', str):
184 sys.stderr.write ('\nNot smart enough to convert to new \\header format')
187 conversions.append (((1,0,2), conv, '\\header { key = concat + with + operator }'))
191 str = re.sub ('\\\\melodic([^a-zA-Z])', '\\\\notes\\1',str)
194 conversions.append (((1,0,3), conv, '\\melodic -> \\notes'))
198 str = re.sub ('default_paper *=', '',str)
199 str = re.sub ('default_midi *=', '',str)
202 conversions.append (((1,0,4), conv, 'default_{paper,midi}'))
206 str = re.sub ('ChoireStaff', 'ChoirStaff',str)
207 str = re.sub ('\\\\output', 'output = ',str)
211 conversions.append (((1,0,5), conv, 'ChoireStaff -> ChoirStaff'))
215 if re.search ('[a-zA-Z]+ = *\\translator',str):
216 sys.stderr.write ('\nNot smart enough to change \\translator syntax')
217 # raise FatalConversionError()
220 conversions.append (((1,0,6), conv, 'foo = \\translator {\\type .. } ->\\translator {\\type ..; foo; }'))
225 str = re.sub ('\\\\lyrics*', '\\\\lyrics',str)
229 conversions.append (((1,0,7), conv, '\\lyric -> \\lyrics'))
233 str = re.sub ('\\\\\\[/3+', '\\\\times 2/3 { ',str)
234 str = re.sub ('\\[/3+', '\\\\times 2/3 { [',str)
235 str = re.sub ('\\\\\\[([0-9/]+)', '\\\\times \\1 {',str)
236 str = re.sub ('\\[([0-9/]+)', '\\\\times \\1 { [',str)
237 str = re.sub ('\\\\\\]([0-9/]+)', '}', str)
238 str = re.sub ('\\\\\\]', '}',str)
239 str = re.sub ('\\]([0-9/]+)', '] }', str)
242 conversions.append (((1,0,10), conv, '[2/3 ]1/1 -> \\times 2/3 '))
247 conversions.append (((1,0,12), conv, 'Chord syntax stuff'))
254 str = re.sub ('<([^>~]+)~([^>]*)>','<\\1 \\2> ~', str)
258 conversions.append (((1,0,13), conv, '<a ~ b> c -> <a b> ~ c'))
262 str = re.sub ('<\\[','[<', str)
263 str = re.sub ('\\]>','>]', str)
267 conversions.append (((1,0,14), conv, '<[a b> <a b]>c -> [<a b> <a b>]'))
272 str = re.sub ('\\\\type([^\n]*engraver)','\\\\TYPE\\1', str)
273 str = re.sub ('\\\\type([^\n]*performer)','\\\\TYPE\\1', str)
274 str = re.sub ('\\\\type','\\\\context', str)
275 str = re.sub ('\\\\TYPE','\\\\type', str)
276 str = re.sub ('textstyle','textStyle', str)
280 conversions.append (((1,0,16), conv, '\\type -> \\context, textstyle -> textStyle'))
285 if re.search ('\\\\repeat',str):
286 sys.stderr.write ('\nNot smart enough to convert \\repeat')
287 # raise FatalConversionError()
290 conversions.append (((1,0,18), conv,
291 '\\repeat NUM Music Alternative -> \\repeat FOLDSTR Music Alternative'))
295 str = re.sub ('SkipBars','skipBars', str)
296 str = re.sub ('fontsize','fontSize', str)
297 str = re.sub ('midi_instrument','midiInstrument', str)
301 conversions.append (((1,0,19), conv,
302 'fontsize -> fontSize, midi_instrument -> midiInstrument, SkipBars -> skipBars'))
307 str = re.sub ('tieydirection','tieVerticalDirection', str)
308 str = re.sub ('slurydirection','slurVerticalDirection', str)
309 str = re.sub ('ydirection','verticalDirection', str)
313 conversions.append (((1,0,20), conv,
314 '{,tie,slur}ydirection -> {v,tieV,slurV}erticalDirection'))
319 str = re.sub ('hshift','horizontalNoteShift', str)
323 conversions.append (((1,0,21), conv,
324 'hshift -> horizontalNoteShift'))
329 str = re.sub ('\\\\grouping[^;]*;','', str)
333 conversions.append (((1,1,52), conv,
334 'deprecate \\grouping'))
339 str = re.sub ('\\\\wheel','\\\\coda', str)
343 conversions.append (((1,1,55), conv,
344 '\\wheel -> \\coda'))
348 str = re.sub ('keyoctaviation','keyOctaviation', str)
349 str = re.sub ('slurdash','slurDash', str)
353 conversions.append (((1,1,65), conv,
354 'slurdash -> slurDash, keyoctaviation -> keyOctaviation'))
358 str = re.sub ('\\\\repeat *\"?semi\"?','\\\\repeat "volta"', str)
362 conversions.append (((1,1,66), conv,
368 str = re.sub ('\"?beamAuto\"? *= *\"?0?\"?','noAutoBeaming = "1"', str)
372 conversions.append (((1,1,67), conv,
373 'beamAuto -> noAutoBeaming'))
377 str = re.sub ('automaticMelismas', 'automaticMelismata', str)
381 conversions.append (((1,2,0), conv,
382 'automaticMelismas -> automaticMelismata'))
386 str = re.sub ('dynamicDir\\b', 'dynamicDirection', str)
390 conversions.append (((1,2,1), conv,
391 'dynamicDir -> dynamicDirection'))
395 str = re.sub ('\\\\cadenza *0 *;', '\\\\cadenzaOff', str)
396 str = re.sub ('\\\\cadenza *1 *;', '\\\\cadenzaOn', str)
400 conversions.append (((1,3,4), conv,
401 '\\cadenza -> \cadenza{On|Off}'))
405 str = re.sub ('"?beamAuto([^"=]+)"? *= *"([0-9]+)/([0-9]+)" *;*',
406 'beamAuto\\1 = #(make-moment \\2 \\3)',
410 conversions.append (((1,3,5), conv, 'beamAuto moment properties'))
414 str = re.sub ('stemStyle',
419 conversions.append (((1,3,17), conv, 'stemStyle -> flagStyle'))
423 str = re.sub ('staffLineLeading',
428 conversions.append (((1,3,18), conv, 'staffLineLeading -> staffSpace'))
433 if re.search ('\\\\repetitions',str):
434 sys.stderr.write ('\nNot smart enough to convert \\repetitions')
435 # raise FatalConversionError()
438 conversions.append (((1,3,23), conv,
439 '\\\\repetitions feature dropped'))
444 str = re.sub ('textEmptyDimension *= *##t',
445 'textNonEmpty = ##f',
447 str = re.sub ('textEmptyDimension *= *##f',
448 'textNonEmpty = ##t',
452 conversions.append (((1,3,35), conv, 'textEmptyDimension -> textNonEmpty'))
456 str = re.sub ("([a-z]+)[ \t]*=[ \t]*\\\\musicalpitch *{([- 0-9]+)} *\n",
457 "(\\1 . (\\2))\n", str)
458 str = re.sub ("\\\\musicalpitch *{([0-9 -]+)}",
459 "\\\\musicalpitch #'(\\1)", str)
460 if re.search ('\\\\notenames',str):
461 sys.stderr.write ('\nNot smart enough to convert to new \\notenames format')
464 conversions.append (((1,3,38), conv, '\musicalpitch { a b c } -> #\'(a b c)'))
469 return '\\key %s;' % string.lower (match.group (1))
471 str = re.sub ("\\\\key ([^;]+);", replace, str)
474 conversions.append (((1,3,39), conv, '\\key A ; ->\\key a;'))
478 if re.search ('\\[:',str):
479 sys.stderr.write ('\nNot smart enough to convert to new tremolo format')
482 conversions.append (((1,3,41), conv,
483 '[:16 c4 d4 ] -> \\repeat "tremolo" 2 { c16 d16 }'))
487 str = re.sub ('Staff_margin_engraver' , 'Instrument_name_engraver', str)
490 conversions.append (((1,3,42), conv,
491 'Staff_margin_engraver deprecated, use Instrument_name_engraver'))
495 str = re.sub ('note[hH]eadStyle\\s*=\\s*"?(\\w+)"?' , "noteHeadStyle = #'\\1", str)
498 conversions.append (((1,3,49), conv,
499 'noteHeadStyle value: string -> symbol'))
503 if re.search ('\\\\keysignature', str):
504 sys.stderr.write ('\nNot smart enough to convert to new tremolo format')
508 conversions.append (((1,3,58), conv,
509 'noteHeadStyle value: string -> symbol'))
513 str = re.sub (r"""\\key *([a-z]+) *;""", r"""\\key \1 \major;""",str);
515 conversions.append (((1,3,59), conv,
516 '\key X ; -> \key X major; '))
520 str = re.sub (r'latexheaders *= *"\\\\input ',
524 conversions.append (((1,3,68), conv, 'latexheaders = "\\input global" -> latexheaders = "global"'))
529 # TODO: lots of other syntax change should be done here as well
532 str = re.sub ('basicCollisionProperties', 'NoteCollision', str)
533 str = re.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
534 str = re.sub ('basicKeyProperties' , "KeySignature", str)
536 str = re.sub ('basicClefItemProperties' ,"Clef", str)
539 str = re.sub ('basicLocalKeyProperties' ,"Accidentals", str)
540 str = re.sub ('basicMarkProperties' ,"Accidentals", str)
541 str = re.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
543 str = re.sub ('Repeat_engraver' ,'Volta_engraver', str)
546 conversions.append (((1,3,92), conv, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
550 # Ugh, but meaning of \stemup changed too
551 # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
552 str = re.sub ('\\\\stemup', '\\\\stemUp', str)
553 str = re.sub ('\\\\stemdown', '\\\\stemDown', str)
554 str = re.sub ('\\\\stemboth', '\\\\stemBoth', str)
556 str = re.sub ('\\\\slurup', '\\\\slurUp', str)
557 str = re.sub ('\\\\slurboth', '\\\\slurBoth', str)
558 str = re.sub ('\\\\slurdown', '\\\\slurDown', str)
559 str = re.sub ('\\\\slurdotted', '\\\\slurDotted', str)
560 str = re.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
562 str = re.sub ('\\\\shiftoff', '\\\\shiftOff', str)
563 str = re.sub ('\\\\shifton', '\\\\shiftOn', str)
564 str = re.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
565 str = re.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
567 str = re.sub ('\\\\onevoice', '\\\\oneVoice', str)
568 str = re.sub ('\\\\voiceone', '\\\\voiceOne', str)
569 str = re.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
570 str = re.sub ('\\\\voicethree', '\\\\voiceThree', str)
571 str = re.sub ('\\\\voicefour', '\\\\voiceFour', str)
573 # I don't know exactly when these happened...
574 # ugh, we loose context setting here...
575 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
576 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
577 str = re.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
579 str = re.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
580 str = re.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
581 str = re.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
583 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
584 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
585 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
587 # (lacks capitalisation slur -> Slur)
588 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
589 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
590 str = re.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
593 str = re.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
594 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
595 str = re.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
597 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
598 str = re.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
600 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
601 str = re.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
607 conversions.append (((1,3,93), conv,
608 'property definiton case (eg. onevoice -> oneVoice)'))
613 str = re.sub ('ChordNames*', 'ChordNames', str)
614 if re.search ('\\\\textscript "[^"]* *"[^"]*"', str):
615 sys.stderr.write ('\nNot smart enough to convert to new \\textscript markup text')
617 str = re.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
621 conversions.append (((1,3,97), conv, 'ChordName -> ChordNames'))
624 # TODO: add lots of these
628 str = re.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
629 str = re.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
631 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
633 str = re.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
635 str = re.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
637 str = re.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
639 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
642 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
644 str = re.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
647 conversions.append (((1,3,98), conv, 'CONTEXT.textStyle -> GROB.#font-style '))
651 str = re.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
652 str = re.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
653 str = re.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
654 str = re.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
659 conversions.append (((1,3,102), conv, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
664 str = re.sub ('\\\\push', '\\\\override', str)
665 str = re.sub ('\\\\pop', '\\\\revert', str)
669 conversions.append (((1,3,111), conv, '\\push -> \\override, \\pop -> \\revert'))
673 str = re.sub ('LyricVoice', 'LyricsVoice', str)
675 str = re.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
676 str = re.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
679 conversions.append (((1,3,113), conv, 'LyricVoice -> LyricsVoice'))
681 def regularize_id (str):
688 elif x in string.digits:
689 x = chr(ord (x) - ord ('0') +ord ('A'))
690 elif x not in string.letters:
692 elif x in string.lowercase and lastx == '_':
701 def regularize_dollar_reference (match):
702 return regularize_id (match.group (1))
703 def regularize_assignment (match):
704 return '\n' + regularize_id (match.group (1)) + ' = '
705 str = re.sub ('\$([^\t\n ]+)', regularize_dollar_reference, str)
706 str = re.sub ('\n([^ \t\n]+) = ', regularize_assignment, str)
709 conversions.append (((1,3,117), conv, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
714 def regularize_paper (match):
715 return regularize_id (match.group (1))
717 str = re.sub ('(paper_[a-z]+)', regularize_paper, str)
718 str = re.sub ('sustainup', 'sustainUp', str)
719 str = re.sub ('nobreak', 'noBreak', str)
720 str = re.sub ('sustaindown', 'sustainDown', str)
721 str = re.sub ('sostenutoup', 'sostenutoUp', str)
722 str = re.sub ('sostenutodown', 'sostenutoDown', str)
723 str = re.sub ('unachorda', 'unaChorda', str)
724 str = re.sub ('trechorde', 'treChorde', str)
728 conversions.append (((1,3,120), conv, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
732 str = re.sub ('drarnChords', 'chordChanges', str)
733 str = re.sub ('\\musicalpitch', '\\pitch', str)
736 conversions.append (((1,3,122), conv, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
740 str = re.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
743 conversions.append (((1,3,136), conv, 'ly-X-elt-property -> ly-X-grob-property'))
747 str = re.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
750 conversions.append (((1,3,138), conv, 'point-and-click argument changed to procedure.'))
754 str = re.sub ('followThread', 'followVoice', str)
755 str = re.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
756 str = re.sub ('FollowThread', 'VoiceFollower', str)
759 conversions.append (((1,3,138), conv, 'followThread -> followVoice.'))
763 str = re.sub ('font-point-size', 'font-design-size', str)
766 conversions.append (((1,3,139), conv, 'font-point-size -> font-design-size.'))
770 str = re.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
773 conversions.append (((1,3,141), conv, 'xNoDots -> xSolid'))
777 str = re.sub ('([Cc])horda', '\\1orda', str)
780 conversions.append (((1,3,144), conv, 'Chorda -> Corda'))
785 str = re.sub ('([A-Za-z]+)MinimumVerticalExtent', 'MinimumV@rticalExtent', str)
786 str = re.sub ('([A-Za-z]+)ExtraVerticalExtent', 'ExtraV@rticalExtent', str)
787 str = re.sub ('([A-Za-z]+)VerticalExtent', 'VerticalExtent', str)
788 str = re.sub ('ExtraV@rticalExtent', 'ExtraVerticalExtent', str)
789 str = re.sub ('MinimumV@rticalExtent', 'MinimumVerticalExtent', str)
792 conversions.append (((1,3,145), conv,
793 'ContextNameXxxxVerticalExtent -> XxxxVerticalExtent'))
795 ################################
797 ################################
799 def get_conversions (from_version, to_version):
800 def version_b (v, f = from_version, t = to_version):
801 return version_cmp (v[0], f) > 0 and version_cmp (v[0], t) <= 0
802 return filter (version_b, conversions)
805 def latest_version ():
806 return conversions[-1][0]
808 def do_conversion (infile, from_version, outfile, to_version):
809 conv_list = get_conversions (from_version, to_version)
811 sys.stderr.write ('Applying conversions: ')
816 sys.stderr.write (tup_to_str (x[0]) + ', ')
818 last_conversion = x[0]
820 except FatalConversionError:
821 sys.stderr.write ('Error while converting; I won\'t convert any further')
824 sys.stderr.write ('\n')
825 new_ver = '\\version \"%s\"' % tup_to_str (last_conversion)
827 # ugh: this all really doesn't help
828 # esp. as current conversion rules are soo incomplete
829 if re.search (lilypond_version_re_str, str):
830 str = re.sub (lilypond_version_re_str,'\\'+new_ver , str)
832 # str = new_ver + '\n' + str
836 return last_conversion
838 class UnknownVersion:
841 def do_one_file (infile_name):
842 sys.stderr.write ('Processing `%s\' ... '% infile_name)
845 outfile_name = infile_name + '.NEW'
846 elif __main__.outfile_name:
847 outfile_name = __main__.outfile_name
849 if __main__.from_version:
850 from_version = __main__.from_version
852 guess = guess_lilypond_version (infile_name)
854 raise UnknownVersion()
855 from_version = str_to_tuple (guess)
857 if __main__.to_version:
858 to_version = __main__.to_version
860 to_version = latest_version ()
864 infile = open (infile_name,'r')
869 outfile = open (outfile_name, 'w')
873 touched = do_conversion (infile, from_version, outfile, to_version)
881 if __main__.edit and touched:
883 os.remove(infile_name + '~')
886 os.rename (infile_name, infile_name + '~')
887 os.rename (infile_name + '.NEW', infile_name)
889 sys.stderr.write ('\n')
898 (options, files) = getopt.getopt (
899 sys.argv[1:], 'ao:f:t:seh', ['assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
904 if o== '--help' or o == '-h':
907 if o == '--version' or o == '-v':
910 elif o== '--from' or o=='-f':
911 from_version = str_to_tuple (a)
912 elif o== '--to' or o=='-t':
913 to_version = str_to_tuple (a)
914 elif o== '--edit' or o == '-e':
916 elif o== '--show-rules' or o == '-s':
917 show_rules (sys.stdout)
919 elif o == '--output' or o == '-o':
921 elif o == '--assume-old' or o == '-a':
933 except UnknownVersion:
934 sys.stderr.write ('\n')
935 sys.stderr.write ("%s: can't determine version for %s" % (program_name, f))
936 sys.stderr.write ('\n')
939 from_version = (0,0,0)
943 sys.stderr.write ("%s: skipping: %s " % (program_name, f))
945 sys.stderr.write ('\n')