Skip to content

Commit de7cb29

Browse files
committed
added -b/--backup option to script
1 parent f31e25a commit de7cb29

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

setversion.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ def rewrite_file(infilename, rewritefunc, ctxt):
9292
infile.close()
9393
outfile.close()
9494
if not ctxt["nodelete"]:
95-
os.remove(infilename)
95+
if ctxt["backup"]:
96+
os.rename(infilename, infilename + ".bak")
97+
else:
98+
os.remove(infilename)
9699
os.rename(outfilename, infilename)
97100

98101

@@ -105,6 +108,8 @@ def main():
105108
parser.add_argument("version", help="New version number to add")
106109
parser.add_argument("-n", "--nodelete", action="store_true",
107110
help="Do not delete existing files, leave new files with .new extension")
111+
parser.add_argument("-b", "--backup", action="store_true",
112+
help="Keep old versions of files around with a .bak extension")
108113

109114
args = parser.parse_args()
110115

@@ -113,7 +118,7 @@ def main():
113118
print("Invalid version number {0}: must be three numeric values separated by dots\n".format(args.version))
114119
return 1
115120

116-
ctxt = {"version": args.version, "nodelete": args.nodelete}
121+
ctxt = {"version": args.version, "nodelete": args.nodelete, "backup": args.backup}
117122
rewrite_file("README.md", readme_rewriter, ctxt)
118123
rewrite_file("docs/changelog.rst", changelog_rewriter, ctxt)
119124
rewrite_file("docs/conf.py", doc_conf_rewriter, ctxt)

0 commit comments

Comments
 (0)