Commit 8a79b938 authored by Flavio TARSETTI's avatar Flavio TARSETTI

Merge branch 'improve_asset_information' into 'master'

Improve asset information

See merge request !72
parents 9d409539 abdb4d1b
Pipeline #29918 passed with stages
in 17 minutes and 49 seconds
......@@ -69,6 +69,9 @@ class Storage(utils.Storage):
``<toolchain-user>`` are the same.
"""
asset_type = "experiment"
asset_folder = "experiments"
def __init__(self, prefix, name):
if name.count(os.sep) not in (3, 4):
......@@ -88,7 +91,9 @@ class Storage(utils.Storage):
)
self.prefix = prefix
path = utils.hashed_or_simple(self.prefix, "experiments", name, suffix=".json")
path = utils.hashed_or_simple(
self.prefix, self.asset_folder, name, suffix=".json"
)
path = path[:-5]
super(Storage, self).__init__(path)
......
......@@ -42,15 +42,12 @@ plotterparameter
Validation for plotterparameters
"""
import os
from . import dataformat
from . import schema
from . import prototypes
from . import utils
from . import loader
from . import plotter
class Storage(utils.Storage):
"""Resolves paths for plotterparameters
......@@ -62,6 +59,9 @@ class Storage(utils.Storage):
``<user>/<plotterparameter-name>/<version>``
"""
asset_type = "plotterparameter"
asset_folder = "plotterparameters"
def __init__(self, prefix, name):
if name.count("/") != 2:
......@@ -71,7 +71,9 @@ class Storage(utils.Storage):
self.fullname = name
self.prefix = prefix
path = utils.hashed_or_simple(self.prefix, "plotterparameters", name, suffix=".json")
path = utils.hashed_or_simple(
self.prefix, self.asset_folder, name, suffix=".json"
)
path = path[:-5]
super(Storage, self).__init__(path)
......@@ -122,12 +124,7 @@ class Plotterparameter(object):
JSON decoder.
"""
def __init__(
self,
prefix,
data,
plotter_cache=None,
):
def __init__(self, prefix, data, plotter_cache=None):
self._name = None
self.storage = None
self.errors = []
......@@ -170,20 +167,21 @@ class Plotterparameter(object):
self._name = data
self.storage = Storage(self.prefix, self._name)
if not self.storage.json.exists():
self.errors.append(f'Plotterparameter declaration file not found: {data}')
self.errors.append(
f"Plotterparameter declaration file not found: {data}"
)
return
data = self.storage.json.path # loads data from JSON declaration
# At this point, `data' can be a dictionary or ``None``
# Either way, assign something valid to `self.data'
if data is None: # use the dummy plotterparameter
if data is None: # use the dummy plotterparameter
self.data, self.errors = prototypes.load("plotterparameter")
assert not self.errors, "\n * %s" % "\n *".join(self.errors)
assert not self.errors, "\n * %s" % "\n *".join(self.errors) # nosec
else:
# this runs basic validation, including JSON loading if required
self.data, self.errors = schema.validate("plotterparameter", data)
def _load_plotter(self, plotter_cache):
"""Loads the plotter for the plotterparameter.
Assumes that `self.data' has been calculated.
......@@ -195,7 +193,7 @@ class Plotterparameter(object):
"""
# find the plotter if it wasnt given
if self.plotter is None:
plotter_name = self.data['plotter']
plotter_name = self.data["plotter"]
pl = None
if plotter_name in plotter_cache:
......@@ -210,22 +208,24 @@ class Plotterparameter(object):
plotter_cache[plotter_name] = pl
self.plotter = pl
def _validate_data(self):
"""Validates that the properties in the plotterparameter's
data properly configure the plotter's fields
"""
for key, val in self.data['data'].items():
for key, val in self.data["data"].items():
try:
self.plotter.clean_parameter(key, val)
except KeyError:
self.errors.append(f"'{key}' isn't a parameter for plotter {self.plotter.name}")
self.errors.append(
f"'{key}' isn't a parameter for plotter {self.plotter.name}"
)
return
except ValueError:
self.errors.append(f"'{value}' is invalid for parameter {key} of plotter {self.plotter.name}")
self.errors.append(
f"'{val}' is invalid for parameter {key} of plotter {self.plotter.name}"
)
return
@property
def valid(self):
"""A boolean that indicates if this plotterparameter is valid or not"""
......
......@@ -62,6 +62,9 @@ class Storage(utils.Storage):
``<user>/<name>/<version>``.
"""
asset_type = "toolchain"
asset_folder = "toolchains"
def __init__(self, prefix, name):
if name.count("/") != 2:
......@@ -71,7 +74,9 @@ class Storage(utils.Storage):
self.fullname = name
self.prefix = prefix
path = utils.hashed_or_simple(self.prefix, "toolchains", name, suffix=".json")
path = utils.hashed_or_simple(
self.prefix, self.asset_folder, name, suffix=".json"
)
path = path[:-5]
super(Storage, self).__init__(path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment