mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Update picture.py
This commit is contained in:
parent
4bbf7c2ed2
commit
30cbfe2154
@ -19,11 +19,10 @@ import os
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import xml.etree.ElementTree as ET
|
|
||||||
|
|
||||||
from gns3server.web.route import Route
|
from gns3server.web.route import Route
|
||||||
from gns3server.controller import Controller
|
from gns3server.controller import Controller
|
||||||
|
from gns3server.utils.picture import get_size
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -56,25 +55,7 @@ class SymbolHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
symbol_id = urllib.parse.unquote(request.match_info["symbol_id"])
|
symbol_id = urllib.parse.unquote(request.match_info["symbol_id"])
|
||||||
try:
|
try:
|
||||||
file_content = open(controller.symbols.get_path(symbol_id), 'r').read()
|
width, height, _ = controller.symbols.get_size(symbol_id)
|
||||||
svg_root = ET.fromstring(file_content)
|
|
||||||
|
|
||||||
svg_width = svg_root.get('width')
|
|
||||||
if svg_width is not None:
|
|
||||||
try:
|
|
||||||
width = int(float(svg_width))
|
|
||||||
except:
|
|
||||||
log.warning("Could not get width for symbol with id: {}".format(symbol_id))
|
|
||||||
width = 0
|
|
||||||
|
|
||||||
svg_height = svg_root.get('height')
|
|
||||||
if svg_height is not None:
|
|
||||||
try:
|
|
||||||
height = int(float(svg_height))
|
|
||||||
except:
|
|
||||||
log.warning("Could not get height for symbol with id: {}".format(symbol_id))
|
|
||||||
height = 0
|
|
||||||
|
|
||||||
symbol_dimensions = { 'width': width, 'height': height }
|
symbol_dimensions = { 'width': width, 'height': height }
|
||||||
response.json(symbol_dimensions)
|
response.json(symbol_dimensions)
|
||||||
except (KeyError, OSError) as e:
|
except (KeyError, OSError) as e:
|
||||||
|
@ -92,7 +92,7 @@ def get_size(data, default_width=0, default_height=0):
|
|||||||
# End of https://github.com/shibukawa/imagesize_py
|
# End of https://github.com/shibukawa/imagesize_py
|
||||||
|
|
||||||
# handle SVG
|
# handle SVG
|
||||||
elif size >= 10 and data.startswith(b'<?xml'):
|
elif size >= 10 and (data.startswith(b'<?xml') or data.startswith(b'<svg')):
|
||||||
filetype = "svg"
|
filetype = "svg"
|
||||||
fhandle = io.BytesIO(data)
|
fhandle = io.BytesIO(data)
|
||||||
tree = ElementTree()
|
tree = ElementTree()
|
||||||
|
Loading…
Reference in New Issue
Block a user