Backup configuration file before overwrite it.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@@ -104,13 +105,16 @@ class ConfigFileTemplate(string.Template):
|
|||||||
|
|
||||||
def copy_from_template(template, dest, context):
|
def copy_from_template(template, dest, context):
|
||||||
"""Create and copy a configuration file from a template."""
|
"""Create and copy a configuration file from a template."""
|
||||||
|
now = datetime.datetime.now().isoformat()
|
||||||
with open(template) as fp:
|
with open(template) as fp:
|
||||||
buf = fp.read()
|
buf = fp.read()
|
||||||
|
if os.path.exists(dest):
|
||||||
|
bak_name = "{}.{}.{}".format(dest, "old", now)
|
||||||
|
shutil.copy(dest, bak_name)
|
||||||
with open(dest, "w") as fp:
|
with open(dest, "w") as fp:
|
||||||
now = datetime.datetime.now()
|
|
||||||
fp.write(
|
fp.write(
|
||||||
"# This file was automatically installed on {}\n"
|
"# This file was automatically installed on {}\n"
|
||||||
.format(now.isoformat()))
|
.format(now))
|
||||||
fp.write(ConfigFileTemplate(buf).substitute(context))
|
fp.write(ConfigFileTemplate(buf).substitute(context))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user