From a437760f5d4f50a0125ee7667f962b38cad0bc00 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 7 Oct 2016 11:29:11 +0200 Subject: [PATCH] Keep forever .gns3 backup before version upgrade --- gns3server/controller/topology.py | 2 +- tests/test_topologies.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index 7cf61b46..85eae314 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -98,7 +98,7 @@ def load_topology(path): if "revision" not in topo or topo["revision"] < GNS3_FILE_FORMAT_REVISION: # If it's an old GNS3 file we need to convert it # 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) with open(path, "w+", encoding="utf-8") as f: json.dump(topo, f) diff --git a/tests/test_topologies.py b/tests/test_topologies.py index b3ffebbc..86b6326a 100644 --- a/tests/test_topologies.py +++ b/tests/test_topologies.py @@ -68,7 +68,7 @@ def test_convert(directory, tmpdir): assert work_topology 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 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) file_path = os.path.join(after_directory, directory, file) # .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)) compare_dict("/", work_topology, after_topology)