[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue 3572: convert-ly should produce several backup files for each invo
From: |
dak |
Subject: |
Issue 3572: convert-ly should produce several backup files for each invokation (issue 14383044) |
Date: |
Fri, 04 Oct 2013 20:05:33 +0000 |
Reviewers: ,
https://codereview.appspot.com/14383044/diff/1/Documentation/usage/updating.itely
File Documentation/usage/updating.itely (right):
https://codereview.appspot.com/14383044/diff/1/Documentation/usage/updating.itely#newcode172
Documentation/usage/updating.itely:172: @item -h,--help
Actually, where is the point in deleting those spaces? It's not done
for -l, and cross-checking with GNU tools shows that their help messages
offset the long option forms with a space. So what gives with this form
of interpunction?
Short of any argument, I'll put the space back in (or in in the first
place) everywhere.
Description:
Issue 3572: convert-ly should produce several backup files for each
invokation
This avoids an unnecessary file check and does several changes to
match our spacing conventions.
Please review this at https://codereview.appspot.com/14383044/
Affected files (+34, -16 lines):
M Documentation/usage/updating.itely
M scripts/convert-ly.py
Index: Documentation/usage/updating.itely
diff --git a/Documentation/usage/updating.itely
b/Documentation/usage/updating.itely
index
98d3fe16db5ec6c99a42e277ba935edbeec78d1c..d33ca21c39aa805e2d5deccf865162006b682ba1
100644
--- a/Documentation/usage/updating.itely
+++ b/Documentation/usage/updating.itely
@@ -156,14 +156,20 @@ 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.
+
address@hidden -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,address@hidden
Set the version to convert from. If this is not set, @command{convert-ly}
will guess this, on the basis of @code{\version} strings in the file.
E.g. @option{--from=2.10.25}
address@hidden -h, --help
address@hidden -h,--help
Print usage help.
@item -l @var{loglevel}, address@hidden
@@ -175,10 +181,10 @@ case, are @code{PROGRESS} (the default), @code{NONE},
@code{WARNING},
Normally, @command{convert-ly} adds a @code{\version} indicator
to the output. Specifying this option suppresses this.
address@hidden -s, --show-rules
address@hidden -s,--show-rules
Show all known conversions and exit.
address@hidden -t, address@hidden
address@hidden -t,address@hidden
Explicitly set which @code{\version} to convert to, otherwise the
default is the most current value. It must be higher than the
starting version.
Index: scripts/convert-ly.py
diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py
index
f3304315428bcce5811b620a656c7d226f728495..641d763713c979c06dfe0621e19959303765403d
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 ()
- Issue 3572: convert-ly should produce several backup files for each invokation (issue 14383044),
dak <=