1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Support image in conversion from old topologies

This commit is contained in:
Julien Duponchelle 2016-07-13 16:37:05 +02:00
parent 8be1e77a2e
commit b841a0f57b
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
5 changed files with 62 additions and 2 deletions

View File

@ -307,11 +307,31 @@ def _convert_1_3_later(topo, topo_path):
"x": int(note["x"]), "x": int(note["x"]),
"y": int(note["y"]), "y": int(note["y"]),
"z": int(note.get("z", 0)), "z": int(note.get("z", 0)),
"rotation": int(ellipse.get("rotation", 0)), "rotation": int(note.get("rotation", 0)),
"svg": svg "svg": svg
} }
new_topo["topology"]["drawings"].append(new_note) new_topo["topology"]["drawings"].append(new_note)
# Images
for image in topo.get("images", []):
img_path = image["path"]
# Absolute image path are rewrite to project specific image
if os.path.abspath(img_path):
try:
os.makedirs(os.path.join(topo_dir, "images"), exist_ok=True)
shutil.copy(img_path, os.path.join(topo_dir, "images", os.path.basename(img_path)))
except OSError:
pass
new_image = {
"drawing_id": str(uuid.uuid4()),
"x": int(image["x"]),
"y": int(image["y"]),
"z": int(image.get("z", 0)),
"rotation": int(image.get("rotation", 0)),
"svg": os.path.basename(img_path)
}
new_topo["topology"]["drawings"].append(new_image)
# Rectangles # Rectangles
for rectangle in topo.get("rectangles", []): for rectangle in topo.get("rectangles", []):
svg = '<svg height="{height}" width="{width}"><rect fill="{fill}" fill-opacity="1.0" height="{height}" width="{width}" {border_style} /></svg>'.format( svg = '<svg height="{height}" width="{width}"><rect fill="{fill}" fill-opacity="1.0" height="{height}" width="{width}" {border_style} /></svg>'.format(
@ -325,7 +345,7 @@ def _convert_1_3_later(topo, topo_path):
"x": int(rectangle["x"]), "x": int(rectangle["x"]),
"y": int(rectangle["y"]), "y": int(rectangle["y"]),
"z": int(rectangle.get("z", 0)), "z": int(rectangle.get("z", 0)),
"rotation": int(ellipse.get("rotation", 0)), "rotation": int(rectangle.get("rotation", 0)),
"svg": svg "svg": svg
} }
new_topo["topology"]["drawings"].append(new_rectangle) new_topo["topology"]["drawings"].append(new_rectangle)

View File

@ -0,0 +1,23 @@
{
"auto_start": false,
"name": "1_5_image",
"project_id": "ANYUUID",
"revision": 5,
"topology": {
"computes": [],
"drawings": [
{
"drawing_id": "ANYUUID",
"rotation": 0,
"svg": "gns3_logo.png",
"x": -64,
"y": -64,
"z": 0
}
],
"links": [],
"nodes": []
},
"type": "topology",
"version": "ANYSTR"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -0,0 +1,17 @@
{
"auto_start": false,
"name": "1_5_image",
"project_id": null,
"revision": 4,
"topology": {
"images": [
{
"path": "images/gns3_logo.png",
"x": -64,
"y": -64
}
]
},
"type": "topology",
"version": "1.5.1dev1"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB