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"'))
528 ################ TODO: lots of other syntax change should be done here as well
534 str = re
.sub ('basicCollisionProperties', 'NoteCollision', str)
535 str = re
.sub ('basicVoltaSpannerProperties' , "VoltaBracket", str)
536 str = re
.sub ('basicKeyProperties' , "KeySignature", str)
538 str = re
.sub ('basicClefItemProperties' ,"Clef", str)
541 str = re
.sub ('basicLocalKeyProperties' ,"Accidentals", str)
542 str = re
.sub ('basicMarkProperties' ,"Accidentals", str)
543 str = re
.sub ('basic([A-Za-z_]+)Properties', '\\1', str)
545 str = re
.sub ('Repeat_engraver' ,'Volta_engraver', str)
548 conversions
.append (((1,3,92), conv
, 'basicXXXProperties -> XXX, Repeat_engraver -> Volta_engraver'))
552 # Ugh, but meaning of \stemup changed too
553 # maybe we should do \stemup -> \stemUp\slurUp\tieUp ?
554 str = re
.sub ('\\\\stemup', '\\\\stemUp', str)
555 str = re
.sub ('\\\\stemdown', '\\\\stemDown', str)
556 str = re
.sub ('\\\\stemboth', '\\\\stemBoth', str)
558 str = re
.sub ('\\\\slurup', '\\\\slurUp', str)
559 str = re
.sub ('\\\\slurboth', '\\\\slurBoth', str)
560 str = re
.sub ('\\\\slurdown', '\\\\slurDown', str)
561 str = re
.sub ('\\\\slurdotted', '\\\\slurDotted', str)
562 str = re
.sub ('\\\\slurnormal', '\\\\slurNoDots', str)
564 str = re
.sub ('\\\\shiftoff', '\\\\shiftOff', str)
565 str = re
.sub ('\\\\shifton', '\\\\shiftOn', str)
566 str = re
.sub ('\\\\shiftonn', '\\\\shiftOnn', str)
567 str = re
.sub ('\\\\shiftonnn', '\\\\shiftOnnn', str)
569 str = re
.sub ('\\\\onevoice', '\\\\oneVoice', str)
570 str = re
.sub ('\\\\voiceone', '\\\\voiceOne', str)
571 str = re
.sub ('\\\\voicetwo', '\\\\voiceTwo', str)
572 str = re
.sub ('\\\\voicethree', '\\\\voiceThree', str)
573 str = re
.sub ('\\\\voicefour', '\\\\voiceFour', str)
575 # I don't know exactly when these happened...
576 # ugh, we loose context setting here...
577 str = re
.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\stemUp\\\\slurUp\\\\tieUp', str)
578 str = re
.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\stemDown\\\\slurDown\\\\tieDown', str)
579 str = re
.sub ('\\\\property *[^ ]*verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\stemBoth\\\\slurBoth\\\\tieBoth', str)
581 str = re
.sub ('verticalDirection[^=]*= *#?"?(1|(\\\\up))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #1', str)
582 str = re
.sub ('verticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #-1', str)
583 str = re
.sub ('verticalDirection[^=]*= *#?"?(0|(\\\\center))"?', 'Stem \\\\override #\'direction = #0\nSlur \\\\override #\'direction = #0\n Tie \\\\override #\'direction = #0', str)
585 str = re
.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\\\1Up', str)
586 str = re
.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\\\1Down', str)
587 str = re
.sub ('\\\\property *[^ .]*[.]?([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\\\\\1Both', str)
589 # (lacks capitalisation slur -> Slur)
590 str = re
.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\1 \\\\override #\'direction = #1', str)
591 str = re
.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?((-1)|(\\\\down))"?', '\\1 \\override #\'direction = #-1', str)
592 str = re
.sub ('([a-z]+)VerticalDirection[^=]*= *#?"?(0|(\\\\center))"?', '\\1 \\\\override #\'direction = #0', str)
595 str = re
.sub ('\\\\property *[^ .]*[.]?dynamicDirection[^=]*= *#?"?(1|(\\\\up))"?', '\\\\dynamicUp', str)
596 str = re
.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?((-1)|(\\\\down))"?', '\\\\dynamicDown', str)
597 str = re
.sub ('\\\\property *[^ .]*[.]?dyn[^=]*= *#?"?(0|(\\\\center))"?', '\\\\dynamicBoth', str)
599 str = re
.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?(0|(""))"?', '\\\\\\1NoDots', str)
600 str = re
.sub ('\\\\property *[^ .]*[.]?([a-z]+)Dash[^=]*= *#?"?([1-9]+)"?', '\\\\\\1Dotted', str)
602 str = re
.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?(0|(""))"?', '\\\\autoBeamOn', str)
603 str = re
.sub ('\\\\property *[^ .]*[.]?noAutoBeaming[^=]*= *#?"?([1-9]+)"?', '\\\\autoBeamOff', str)
609 conversions
.append (((1,3,93), conv
,
610 'property definiton case (eg. onevoice -> oneVoice)'))
615 str = re
.sub ('ChordNames*', 'ChordNames', str)
616 if re
.search ('\\\\textscript "[^"]* *"[^"]*"', str):
617 sys
.stderr
.write ('\nNot smart enough to convert to new \\textscript markup text')
619 str = re
.sub ('\\textscript +("[^"]*")', '\\textscript #\\1', str)
623 conversions
.append (((1,3,97), conv
, 'ChordName -> ChordNames'))
626 ## TODO: add lots of these
630 str = re
.sub ('\\\\property *"?Voice"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Voice.TextScript \\\\set #\'font-style = #\'\\1', str)
631 str = re
.sub ('\\\\property *"?Lyrics"? *[.] *"?textStyle"? *= *"([^"]*)"', '\\\\property Lyrics.LyricText \\\\set #\'font-style = #\'\\1', str)
633 str = re
.sub ('\\\\property *"?([^.]+)"? *[.] *"?timeSignatureStyle"? *= *"([^"]*)"', '\\\\property \\1.TimeSignature \\\\override #\'style = #\'\\2', str)
635 str = re
.sub ('"?timeSignatureStyle"? *= *#?""', 'TimeSignature \\\\override #\'style = ##f', str)
637 str = re
.sub ('"?timeSignatureStyle"? *= *#?"([^"]*)"', 'TimeSignature \\\\override #\'style = #\'\\1', str)
639 str = re
.sub ('#\'style *= #*"([^"])"', '#\'style = #\'\\1', str)
641 str = re
.sub ('\\\\property *"?([^.]+)"? *[.] *"?horizontalNoteShift"? *= *"?#?([-0-9]+)"?', '\\\\property \\1.NoteColumn \\\\override #\'horizontal-shift = #\\2', str)
644 str = re
.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *""', '\\\\property \\1.Stem \\\\override #\'flag-style = ##f', str)
646 str = re
.sub ('\\\\property *"?([^.]+)"? *[.] *"?flagStyle"? *= *"([^"]*)"', '\\\\property \\1.Stem \\\\override #\'flag-style = #\'\\2', str)
649 conversions
.append (((1,3,98), conv
, 'CONTEXT.textStyle -> GROB.#font-style '))
653 str = re
.sub ('"?beamAutoEnd_([0-9]*)"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end 1 \\1 * *) = \\2', str)
654 str = re
.sub ('"?beamAutoBegin_([0-9]*)"? *= *(#\\([^)]*\))', 'autoBeamSettings \\push #\'(begin 1 \\1 * *) = \\2', str)
655 str = re
.sub ('"?beamAutoEnd"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(end * * * *) = \\1', str)
656 str = re
.sub ('"?beamAutoBegin"? *= *(#\\([^)]*\\))', 'autoBeamSettings \\push #\'(begin * * * *) = \\1', str)
661 conversions
.append (((1,3,102), conv
, 'beamAutoEnd -> autoBeamSettings \\push (end * * * *)'))
666 str = re
.sub ('\\\\push', '\\\\override', str)
667 str = re
.sub ('\\\\pop', '\\\\revert', str)
671 conversions
.append (((1,3,111), conv
, '\\push -> \\override, \\pop -> \\revert'))
675 str = re
.sub ('LyricVoice', 'LyricsVoice', str)
677 str = re
.sub ('Chord[Nn]ames*.Chord[Nn]ames*', 'ChordNames.ChordName', str)
678 str = re
.sub ('Chord[Nn]ames([ \t\n]+\\\\override)', 'ChordName\\1', str)
681 conversions
.append (((1,3,113), conv
, 'LyricVoice -> LyricsVoice'))
683 def regularize_id (str):
690 elif x
in string
.digits
:
691 x
= chr(ord (x
) - ord ('0') +ord ('A'))
692 elif x
not in string
.letters
:
694 elif x
in string
.lowercase
and lastx
== '_':
703 def regularize_dollar_reference (match
):
704 return regularize_id (match
.group (1))
705 def regularize_assignment (match
):
706 return '\n' + regularize_id (match
.group (1)) + ' = '
707 str = re
.sub ('\$([^\t\n ]+)', regularize_dollar_reference
, str)
708 str = re
.sub ('\n([^ \t\n]+) = ', regularize_assignment
, str)
711 conversions
.append (((1,3,117), conv
, 'identifier names: $!foo_bar_123 -> xfooBarABC'))
716 def regularize_paper (match
):
717 return regularize_id (match
.group (1))
719 str = re
.sub ('(paper_[a-z]+)', regularize_paper
, str)
720 str = re
.sub ('sustainup', 'sustainUp', str)
721 str = re
.sub ('nobreak', 'noBreak', str)
722 str = re
.sub ('sustaindown', 'sustainDown', str)
723 str = re
.sub ('sostenutoup', 'sostenutoUp', str)
724 str = re
.sub ('sostenutodown', 'sostenutoDown', str)
725 str = re
.sub ('unachorda', 'unaChorda', str)
726 str = re
.sub ('trechorde', 'treChorde', str)
730 conversions
.append (((1,3,120), conv
, 'paper_xxx -> paperXxxx, pedalup -> pedalUp.'))
734 str = re
.sub ('drarnChords', 'chordChanges', str)
735 str = re
.sub ('\\musicalpitch', '\\pitch', str)
738 conversions
.append (((1,3,122), conv
, 'drarnChords -> chordChanges, \\musicalpitch -> \\pitch'))
742 str = re
.sub ('ly-([sg])et-elt-property', 'ly-\\1et-grob-property', str)
745 conversions
.append (((1,3,136), conv
, 'ly-X-elt-property -> ly-X-grob-property'))
749 str = re
.sub ('point-and-click +#t', 'point-and-click line-column-location', str)
752 conversions
.append (((1,3,138), conv
, 'point-and-click argument changed to procedure.'))
756 str = re
.sub ('followThread', 'followVoice', str)
757 str = re
.sub ('Thread.FollowThread', 'Voice.VoiceFollower', str)
758 str = re
.sub ('FollowThread', 'VoiceFollower', str)
761 conversions
.append (((1,3,138), conv
, 'followThread -> followVoice.'))
765 str = re
.sub ('font-point-size', 'font-design-size', str)
768 conversions
.append (((1,3,139), conv
, 'font-point-size -> font-design-size.'))
772 str = re
.sub ('([a-zA-Z]*)NoDots', '\\1Solid', str)
775 conversions
.append (((1,3,141), conv
, 'xNoDots -> xSolid'))
779 str = re
.sub ('([Cc])horda', '\\1orda', str)
782 conversions
.append (((1,3,144), conv
, 'Chorda -> Corda'))
785 ############################
788 def get_conversions (from_version
, to_version
):
789 def version_b (v
, f
= from_version
, t
= to_version
):
790 return version_cmp (v
[0], f
) > 0 and version_cmp (v
[0], t
) <= 0
791 return filter (version_b
, conversions
)
794 def latest_version ():
795 return conversions
[-1][0]
797 def do_conversion (infile
, from_version
, outfile
, to_version
):
798 conv_list
= get_conversions (from_version
, to_version
)
800 sys
.stderr
.write ('Applying conversions: ')
805 sys
.stderr
.write (tup_to_str (x
[0]) + ', ')
807 last_conversion
= x
[0]
809 except FatalConversionError
:
810 sys
.stderr
.write ('Error while converting; I won\'t convert any further')
813 sys
.stderr
.write ('\n')
814 new_ver
= '\\version \"%s\"' % tup_to_str (last_conversion
)
816 # ugh: this all really doesn't help
817 # esp. as current conversion rules are soo incomplete
818 if re
.search (lilypond_version_re_str
, str):
819 str = re
.sub (lilypond_version_re_str
,'\\'+new_ver
, str)
821 # str = new_ver + '\n' + str
825 return last_conversion
827 class UnknownVersion
:
830 def do_one_file (infile_name
):
831 sys
.stderr
.write ('Processing `%s\' ... '% infile_name
)
834 outfile_name
= infile_name
+ '.NEW'
835 elif __main__
.outfile_name
:
836 outfile_name
= __main__
.outfile_name
838 if __main__
.from_version
:
839 from_version
= __main__
.from_version
841 guess
= guess_lilypond_version (infile_name
)
843 raise UnknownVersion()
844 from_version
= str_to_tuple (guess
)
846 if __main__
.to_version
:
847 to_version
= __main__
.to_version
849 to_version
= latest_version ()
853 infile
= open (infile_name
,'r')
858 outfile
= open (outfile_name
, 'w')
862 touched
= do_conversion (infile
, from_version
, outfile
, to_version
)
870 if __main__
.edit
and touched
:
872 os
.remove(infile_name
+ '~')
875 os
.rename (infile_name
, infile_name
+ '~')
876 os
.rename (infile_name
+ '.NEW', infile_name
)
878 sys
.stderr
.write ('\n')
887 (options
, files
) = getopt
.getopt (
888 sys
.argv
[1:], 'ao:f:t:seh', ['assume-old', 'version', 'output', 'show-rules', 'help', 'edit', 'from=', 'to='])
893 if o
== '--help' or o
== '-h':
896 if o
== '--version' or o
== '-v':
899 elif o
== '--from' or o
=='-f':
900 from_version
= str_to_tuple (a
)
901 elif o
== '--to' or o
=='-t':
902 to_version
= str_to_tuple (a
)
903 elif o
== '--edit' or o
== '-e':
905 elif o
== '--show-rules' or o
== '-s':
906 show_rules (sys
.stdout
)
908 elif o
== '--output' or o
== '-o':
910 elif o
== '--assume-old' or o
== '-a':
922 except UnknownVersion
:
923 sys
.stderr
.write ('\n')
924 sys
.stderr
.write ("%s: can't determine version for %s" % (program_name
, f
))
925 sys
.stderr
.write ('\n')
928 from_version
= (0,0,0)
932 sys
.stderr
.write ("%s: skipping: %s " % (program_name
, f
))
934 sys
.stderr
.write ('\n')