Compute node size on server

Fix #620
This commit is contained in:
Julien Duponchelle committed 2016-08-17 11:58:19 +02:00
1 parent 938696032c
commit f82527e253
5 files changed
+53 -19

No files matched your search

+20 -17
View File
@@ -31,7 +31,7 @@ log = logging.getLogger(__name__)
class Node:
# This properties are used only on controller and are not forwarded to the compute
CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "symbol", "label", "console_host"]
CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "width", "height", "symbol", "label", "console_host"]
def __init__(self, project, compute, name, node_id=None, node_type=None, **kwargs):
"""
@@ -69,20 +69,26 @@ class Node:
self._command_line = None
self._node_directory = None
self._status = "stopped"
self._width = 70
self._height = 70
self._x = 0
self._y = 0
self._z = 0
self._symbol = ":/symbols/computer.svg"
self._symbol = None
# Update node properties with additional elements
# This properties will be recompute
ignore_properties = ("width", "height")
for prop in kwargs:
try:
setattr(self, prop, kwargs[prop])
except AttributeError as e:
log.critical("Can't set attribute %s", prop)
raise e
if prop not in ignore_properties:
try:
setattr(self, prop, kwargs[prop])
except AttributeError as e:
log.critical("Can't set attribute %s", prop)
raise e
if self._symbol is None:
self.symbol = ":/symbols/computer.svg"
@property
def id(self):
@@ -173,18 +179,10 @@ class Node:
def width(self):
return self._width
@width.setter
def width(self, val):
self._width = val
@property
def height(self):
return self._height
@height.setter
def height(self, val):
self._height = val
@property
def symbol(self):
return self._symbol
@@ -192,6 +190,11 @@ class Node:
@symbol.setter
def symbol(self, val):
self._symbol = val
try:
self._width, self._height, filetype = self._project.controller.symbols.get_size(val)
# If symbol is invalid we replace it by default
except (ValueError, OSError):
self.symbol = ":/symbols/computer.svg"
@property
def label(self):
+12
View File
@@ -19,6 +19,7 @@ import os
from ..utils.get_resource import get_resource
from ..utils.picture import get_size
from ..config import Config
@@ -29,6 +30,8 @@ class Symbols:
def __init__(self):
self.list()
# Keep a cache of symbols size
self._symbol_size_cache = {}
def list(self):
self._symbols_path = {}
@@ -68,3 +71,12 @@ class Symbols:
def get_path(self, symbol_id):
return self._symbols_path[symbol_id]
def get_size(self, symbol_id):
try:
return self._symbol_size_cache[symbol_id]
except KeyError:
with open(self.get_path(symbol_id), "rb") as f:
res = get_size(f.read())
self._symbol_size_cache[symbol_id] = res
return res