mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Support image in conversion from old topologies
This commit is contained in:
parent
8be1e77a2e
commit
b841a0f57b
@ -307,11 +307,31 @@ def _convert_1_3_later(topo, topo_path):
|
||||
"x": int(note["x"]),
|
||||
"y": int(note["y"]),
|
||||
"z": int(note.get("z", 0)),
|
||||
"rotation": int(ellipse.get("rotation", 0)),
|
||||
"rotation": int(note.get("rotation", 0)),
|
||||
"svg": svg
|
||||
}
|
||||
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
|
||||
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(
|
||||
@ -325,7 +345,7 @@ def _convert_1_3_later(topo, topo_path):
|
||||
"x": int(rectangle["x"]),
|
||||
"y": int(rectangle["y"]),
|
||||
"z": int(rectangle.get("z", 0)),
|
||||
"rotation": int(ellipse.get("rotation", 0)),
|
||||
"rotation": int(rectangle.get("rotation", 0)),
|
||||
"svg": svg
|
||||
}
|
||||
new_topo["topology"]["drawings"].append(new_rectangle)
|
||||
|
23
tests/topologies/1_5_images/after/1_5_image.gns3
Normal file
23
tests/topologies/1_5_images/after/1_5_image.gns3
Normal 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 |
17
tests/topologies/1_5_images/before/1_5_image.gns3
Normal file
17
tests/topologies/1_5_images/before/1_5_image.gns3
Normal 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 |
Loading…
Reference in New Issue
Block a user