@item -e, --edit
Apply the conversions direct to the input file, modifying it
-in-place.
+in-place. The original file is renamed as @file{myfile.ly~}. This
+backup file may be a hidden file on some operating systems.
+
+@item -b, --backup-numbered
+When used with the @samp{-e} option, number the backup files so that
+no previous version is overwritten. The backup files may be hidden
+on some operating systems.
@item -f, --from=@var{from-patchlevel}
Set the version to convert from. If this is not set, @command{convert-ly}
import os
import sys
import re
+import shutil
"""
@relocate-preamble@
action='store_true',
dest='diff_version_update',
default=False)
-
+
p.add_option ("-s", '--show-rules',
help=_ ("show rules [default: -f 0, -t %s]") % program_version,
dest='show_rules',
action='store_true', default=False)
-
+
p.add_option ('-t', '--to',
help=_ ("convert to VERSION [default: %s]") % program_version,
metavar=_ ('VERSION'),
action='store',
dest="to_version",
default='')
+
+ p.add_option ('-b', '--backup-numbered',
+ help=_ ("make a numbered backup [default: filename.ext~]"),
+ action='store_true',
+ dest="backup_numbered",
+ default='')
+
p.add_option ('-w', '--warranty', help=_ ("show warranty and copyright"),
action='store_true',
),
return p
-
-
def str_to_tuple (s):
return tuple ([int(n) for n in s.split ('.')])
return (last_conversion, last_change, str, errors)
-
-
def guess_lilypond_version (input):
m = lilypond_version_strict_re.search (input)
if m:
def __init__ (self, version):
self.version = version
+def back_up (file, numbered):
+ if numbered:
+ n = 0
+ while True:
+ n = n + 1
+ back_up = file + '.~' + str(n) + '~'
+ if not os.path.exists (back_up):
+ break
+ else:
+ back_up = file + '~'
+ shutil.copy2 (file, back_up)
+ return back_up
+
def do_one_file (infile_name):
ly.progress (_ (u"Processing `%s\'... ") % infile_name, True)
ly.progress ('\n')
if global_options.edit:
- try:
- os.remove (infile_name + '~')
- except:
- pass
- os.rename (infile_name, infile_name + '~')
+ backup = back_up (infile_name, global_options.backup_numbered)
outfile = open (infile_name, 'w')
else:
outfile = sys.stdout
"There were %d errors.", errors) % errors)
sys.exit (1)
-
main ()