Fix an issue with old symbols paths

This commit is contained in:
Julien Duponchelle 2016-09-15 18:21:39 +02:00
parent da5e3d0e54
commit 37f972dea1
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 24 additions and 3 deletions

View File

@ -204,6 +204,10 @@ class Node:
@symbol.setter
def symbol(self, val):
# No abs path, fix them (bug of 1.X)
if not val.startswith(":") and os.path.abspath(val):
val = os.path.basename(val)
self._symbol = val
try:
self._width, self._height, filetype = self._project.controller.symbols.get_size(val)

View File

@ -70,6 +70,11 @@ class Symbols:
return directory
def get_path(self, symbol_id):
try:
return self._symbols_path[symbol_id]
# Symbol not found refresh cache
except KeyError:
self.list()
return self._symbols_path[symbol_id]
def get_size(self, symbol_id):

View File

@ -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 shutil
import aiohttp
import pytest
import uuid
@ -188,7 +189,7 @@ def test_create_image_missing(node, compute, project, async_run):
node._upload_missing_image.called is True
def test_symbol(node):
def test_symbol(node, symbols_dir):
"""
Change symbol should change the node size
"""
@ -203,11 +204,22 @@ def test_symbol(node):
assert node.symbol == ":/symbols/cloud.svg"
assert node.width == 159
assert node.height == 71
assert node.label["x"] is None
assert node.label["y"] == -40
assert node.label["style"] == "font-size: 10;font-familly: Verdana"
shutil.copy(os.path.join("gns3server", "symbols", "cloud.svg"), os.path.join(symbols_dir, "cloud2.svg"))
node.symbol = "cloud2.svg"
assert node.symbol == "cloud2.svg"
assert node.width == 159
assert node.height == 71
# No abs path, fix them (bug of 1.5)
node.symbol = "/tmp/cloud2.svg"
assert node.symbol == "cloud2.svg"
assert node.width == 159
assert node.height == 71
def test_label_with_default_label_font(node):
"""