1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Keep forever .gns3 backup before version upgrade

This commit is contained in:
Julien Duponchelle 2016-10-07 11:29:11 +02:00
parent 98480881a3
commit a437760f5d
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 3 additions and 3 deletions

View File

@ -98,7 +98,7 @@ def load_topology(path):
if "revision" not in topo or topo["revision"] < GNS3_FILE_FORMAT_REVISION: if "revision" not in topo or topo["revision"] < GNS3_FILE_FORMAT_REVISION:
# If it's an old GNS3 file we need to convert it # If it's an old GNS3 file we need to convert it
# first we backup the file # first we backup the file
shutil.copy(path, path + ".backup") shutil.copy(path, path + ".backup{}".format(topo.get("revision", 0)))
topo = _convert_1_3_later(topo, path) topo = _convert_1_3_later(topo, path)
with open(path, "w+", encoding="utf-8") as f: with open(path, "w+", encoding="utf-8") as f:
json.dump(topo, f) json.dump(topo, f)

View File

@ -68,7 +68,7 @@ def test_convert(directory, tmpdir):
assert work_topology assert work_topology
if "revision" not in before_topology or before_topology["revision"] < GNS3_FILE_FORMAT_REVISION: if "revision" not in before_topology or before_topology["revision"] < GNS3_FILE_FORMAT_REVISION:
assert os.path.exists(os.path.join(work_directory, gns3_file + ".backup")) assert os.path.exists(os.path.join(work_directory, gns3_file + ".backup{}".format(before_topology.get("revision", 0))))
# We should have the same file in after directory and the work directory # We should have the same file in after directory and the work directory
for root, dirs, files in os.walk(after_directory): for root, dirs, files in os.walk(after_directory):
@ -92,7 +92,7 @@ def test_convert(directory, tmpdir):
directory = os.path.relpath(root, work_directory) directory = os.path.relpath(root, work_directory)
file_path = os.path.join(after_directory, directory, file) file_path = os.path.join(after_directory, directory, file)
# .backup are created by the conversion process # .backup are created by the conversion process
if not file.endswith(".backup"): if ".backup" not in file_path:
assert os.path.exists(file_path), "{} should not be here".format(os.path.join(directory, file)) assert os.path.exists(file_path), "{} should not be here".format(os.path.join(directory, file))
compare_dict("/", work_topology, after_topology) compare_dict("/", work_topology, after_topology)