diff options
author | David Kastrup <dak@gnu.org> | 2013-10-04 17:55:24 +0200 |
---|---|---|
committer | David Kastrup <dak@gnu.org> | 2013-10-11 13:43:44 +0200 |
commit | b381556a3132e765159edc75107b31259dbf5988 (patch) | |
tree | 026252bebd616945cfd80bf2909ed3bb92411037 | |
parent | 1d136d4974b57ac7b3e4401e1cde5ea897e1e91b (diff) |
Issue 3572: convert-ly should produce several backup files for each invokation
This supports and documents the -b option for numbered backups. This
was actually written primarily by Eluze.
-rw-r--r-- | Documentation/usage/updating.itely | 8 | ||||
-rw-r--r-- | scripts/convert-ly.py | 36 |
2 files changed, 31 insertions, 13 deletions
diff --git a/Documentation/usage/updating.itely b/Documentation/usage/updating.itely index a32489c39d..06a960ac8a 100644 --- a/Documentation/usage/updating.itely +++ b/Documentation/usage/updating.itely @@ -156,7 +156,13 @@ the version will reflect the last @emph{attempted} conversion. @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} diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index f330431542..641d763713 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -24,6 +24,7 @@ import os import sys import re +import shutil """ @relocate-preamble@ @@ -129,18 +130,25 @@ def get_option_parser (): 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', ), @@ -152,8 +160,6 @@ def get_option_parser (): return p - - def str_to_tuple (s): return tuple ([int(n) for n in s.split ('.')]) @@ -213,8 +219,6 @@ string and the number of errors.""" return (last_conversion, last_change, str, errors) - - def guess_lilypond_version (input): m = lilypond_version_strict_re.search (input) if m: @@ -235,6 +239,19 @@ class InvalidVersion (Exception): 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) @@ -297,11 +314,7 @@ def do_one_file (infile_name): 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 @@ -373,5 +386,4 @@ def main (): "There were %d errors.", errors) % errors) sys.exit (1) - main () |