|
|
|
@ -38,7 +38,7 @@ from .project_manager import ProjectManager
|
|
|
|
|
from .nios.nio_udp import NIOUDP
|
|
|
|
|
from .nios.nio_tap import NIOTAP
|
|
|
|
|
from .nios.nio_ethernet import NIOEthernet
|
|
|
|
|
from ..utils.images import md5sum, remove_checksum
|
|
|
|
|
from ..utils.images import md5sum, remove_checksum, images_directories
|
|
|
|
|
from .error import NodeError, ImageMissingError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -389,24 +389,6 @@ class BaseManager:
|
|
|
|
|
assert nio is not None
|
|
|
|
|
return nio
|
|
|
|
|
|
|
|
|
|
def images_directories(self):
|
|
|
|
|
"""
|
|
|
|
|
Return all directory where we will look for images
|
|
|
|
|
by priority
|
|
|
|
|
"""
|
|
|
|
|
server_config = self.config.get_section_config("Server")
|
|
|
|
|
|
|
|
|
|
paths = []
|
|
|
|
|
img_directory = self.get_images_directory()
|
|
|
|
|
os.makedirs(img_directory, exist_ok=True)
|
|
|
|
|
paths.append(img_directory)
|
|
|
|
|
for directory in server_config.get("additional_images_path", "").split(":"):
|
|
|
|
|
paths.append(directory)
|
|
|
|
|
# Compatibility with old topologies we look in parent directory
|
|
|
|
|
paths.append(os.path.normpath(os.path.join(self.get_images_directory(), '..')))
|
|
|
|
|
# Return only the existings paths
|
|
|
|
|
return [force_unix_path(p) for p in paths if os.path.exists(p)]
|
|
|
|
|
|
|
|
|
|
def get_abs_image_path(self, path):
|
|
|
|
|
"""
|
|
|
|
|
Get the absolute path of an image
|
|
|
|
@ -417,6 +399,7 @@ class BaseManager:
|
|
|
|
|
|
|
|
|
|
if not path:
|
|
|
|
|
return ""
|
|
|
|
|
orig_path = path
|
|
|
|
|
|
|
|
|
|
server_config = self.config.get_section_config("Server")
|
|
|
|
|
img_directory = self.get_images_directory()
|
|
|
|
@ -427,8 +410,7 @@ class BaseManager:
|
|
|
|
|
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
|
|
|
|
|
|
|
|
|
|
if not os.path.isabs(path):
|
|
|
|
|
orig_path = path
|
|
|
|
|
for directory in self.images_directories():
|
|
|
|
|
for directory in images_directories(self._NODE_TYPE):
|
|
|
|
|
path = self._recursive_search_file_in_directory(directory, orig_path)
|
|
|
|
|
if path:
|
|
|
|
|
return force_unix_path(path)
|
|
|
|
@ -438,21 +420,21 @@ class BaseManager:
|
|
|
|
|
path = force_unix_path(os.path.join(self.get_images_directory(), *s))
|
|
|
|
|
if os.path.exists(path):
|
|
|
|
|
return path
|
|
|
|
|
raise ImageMissingError(path)
|
|
|
|
|
raise ImageMissingError(orig_path)
|
|
|
|
|
|
|
|
|
|
# For non local server we disallow using absolute path outside image directory
|
|
|
|
|
if server_config.get("local", False) is True:
|
|
|
|
|
path = force_unix_path(path)
|
|
|
|
|
if os.path.exists(path):
|
|
|
|
|
return path
|
|
|
|
|
raise ImageMissingError(path)
|
|
|
|
|
raise ImageMissingError(orig_path)
|
|
|
|
|
|
|
|
|
|
path = force_unix_path(path)
|
|
|
|
|
for directory in self.images_directories():
|
|
|
|
|
for directory in images_directories(self._NODE_TYPE):
|
|
|
|
|
if os.path.commonprefix([directory, path]) == directory:
|
|
|
|
|
if os.path.exists(path):
|
|
|
|
|
return path
|
|
|
|
|
raise ImageMissingError(path)
|
|
|
|
|
raise ImageMissingError(orig_path)
|
|
|
|
|
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, self.get_images_directory()))
|
|
|
|
|
|
|
|
|
|
def _recursive_search_file_in_directory(self, directory, searched_file):
|
|
|
|
@ -485,7 +467,7 @@ class BaseManager:
|
|
|
|
|
if not path:
|
|
|
|
|
return ""
|
|
|
|
|
path = force_unix_path(self.get_abs_image_path(path))
|
|
|
|
|
for directory in self.images_directories():
|
|
|
|
|
for directory in images_directories(self._NODE_TYPE):
|
|
|
|
|
if os.path.commonprefix([directory, path]) == directory:
|
|
|
|
|
return os.path.relpath(path, directory)
|
|
|
|
|
return path
|
|
|
|
|