From 3dccfbb852dd9e586c8606eb8ccb3fe5443ebd4d Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 13 Jul 2016 09:58:53 +0200 Subject: [PATCH] Migration to 2.0 rename instructions.txt to README.txt Fix #612 --- gns3server/controller/topology.py | 15 ++++++++++++--- tests/topologies/1_5_builtins/after/README.txt | 1 + .../1_5_builtins/before/instructions.txt | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/topologies/1_5_builtins/after/README.txt create mode 100644 tests/topologies/1_5_builtins/before/instructions.txt diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index d941d1c3..c0457467 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os import json import jsonschema import uuid @@ -90,7 +91,7 @@ def load_topology(path): # If it's an old GNS3 file we need to convert it # first we backup the file shutil.copy(path, path + ".backup") - topo = _convert_1_3_later(topo) + topo = _convert_1_3_later(topo, path) with open(path, "w+") as f: json.dump(topo, f) elif topo["revision"] > GNS3_FILE_FORMAT_REVISION: @@ -99,12 +100,14 @@ def load_topology(path): return topo -def _convert_1_3_later(topo): +def _convert_1_3_later(topo, topo_path): """ - Convert topologies to the new file format + Convert topologies from 1_3 to the new file format Look in tests/topologies/README.rst for instructions to test changes here """ + topo_dir = os.path.dirname(topo_path) + new_topo = { "type": "topology", "revision": GNS3_FILE_FORMAT_REVISION, @@ -327,6 +330,12 @@ def _convert_1_3_later(topo): } new_topo["topology"]["drawings"].append(new_rectangle) + # Convert instructions.txt to README.txt + instructions_path = os.path.join(topo_dir, "instructions.txt") + readme_path = os.path.join(topo_dir, "README.txt") + if os.path.exists(instructions_path) and not os.path.exists(readme_path): + shutil.move(instructions_path, readme_path) + return new_topo diff --git a/tests/topologies/1_5_builtins/after/README.txt b/tests/topologies/1_5_builtins/after/README.txt new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/tests/topologies/1_5_builtins/after/README.txt @@ -0,0 +1 @@ +hello diff --git a/tests/topologies/1_5_builtins/before/instructions.txt b/tests/topologies/1_5_builtins/before/instructions.txt new file mode 100644 index 00000000..ce013625 --- /dev/null +++ b/tests/topologies/1_5_builtins/before/instructions.txt @@ -0,0 +1 @@ +hello