mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-24 15:58:08 +00:00
parent
2c62b1eeb8
commit
3dccfbb852
@ -15,6 +15,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
1
tests/topologies/1_5_builtins/after/README.txt
Normal file
1
tests/topologies/1_5_builtins/after/README.txt
Normal file
@ -0,0 +1 @@
|
||||
hello
|
1
tests/topologies/1_5_builtins/before/instructions.txt
Normal file
1
tests/topologies/1_5_builtins/before/instructions.txt
Normal file
@ -0,0 +1 @@
|
||||
hello
|
Loading…
Reference in New Issue
Block a user