Commit adad9d5f authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[common] Refactor handling of Plotterparameter

This asset also has a storage therefore properly handle it.
parent e961fc91
......@@ -53,6 +53,7 @@ from beat.core import dataformat
from beat.core import database
from beat.core import library
from beat.core import plotter
from beat.core import plotterparameter
from beat.core import protocoltemplate
from beat.core import algorithm
from beat.core import toolchain
......@@ -94,6 +95,7 @@ TYPE_VALIDATOR = {
"library": library.Library,
"algorithm": algorithm.Algorithm,
"plotter": plotter.Plotter,
"plotterparameter": plotterparameter.Plotterparameter,
"protocoltemplate": protocoltemplate.ProtocolTemplate,
"toolchain": toolchain.Toolchain,
"experiment": experiment.Experiment,
......@@ -105,14 +107,15 @@ TYPE_STORAGE = {
"library": library.Storage,
"algorithm": algorithm.Storage,
"plotter": plotter.Storage,
"plotterparameter": plotterparameter.Storage,
"protocoltemplate": protocoltemplate.Storage,
"toolchain": toolchain.Storage,
"experiment": experiment.Storage,
}
NOSTORAGE = ["plotterparameter"]
NOSTORAGE = []
TYPE_NOSTORAGE = {"plotterparameter": "plotterparameters"}
TYPE_NOSTORAGE = {}
TYPE_PLURAL = {
"dataformat": "dataformats",
......@@ -159,19 +162,12 @@ class Selector(object):
"algorithm",
"library",
"toolchain",
"experiment",
"plotter",
"plotterparameter",
"protocoltemplate",
]
self.__forkables = [
"dataformat",
"database",
"algorithm",
"library",
"toolchain",
"experiment",
"protocoltemplate",
]
self.__forkables = self.__versionables + ["experiment"]
if os.path.exists(self.path):
self.load()
......@@ -214,30 +210,36 @@ class Selector(object):
return self.__fork[type].get(name)
def version(self, type, src, dst):
def version(self, type_, src, dst):
"""Registers that object ``dst`` is a new version of object ``src``"""
if not type_ in self.__version:
raise RuntimeError("Can't create new version of {}".format(type_))
logger.info(
"`%s/%s' is a new version of `%s/%s'",
TYPE_PLURAL[type],
TYPE_PLURAL[type_],
dst,
TYPE_PLURAL[type],
TYPE_PLURAL[type_],
src,
)
self.__version[type][dst] = src
self.__version[type_][dst] = src
def version_of(self, type, name):
def version_of(self, type_, name):
"""Returns the name of the originating version object or ``None``"""
return self.__version[type].get(name)
if type_ not in self.__version:
return None
def delete(self, type, name):
return self.__version[type_].get(name)
def delete(self, type_, name):
"""Forgets about an object that was being tracked"""
if name in self.__fork[type]:
del self.__fork[type][name]
if name in self.__version[type]:
del self.__version[type][name]
if name in self.__fork[type_]:
del self.__fork[type_][name]
if type_ in self.__version and name in self.__version[type_]:
del self.__version[type_][name]
def load(self):
"""Loads contents from file"""
......@@ -923,7 +925,16 @@ def pull(webapi, prefix, type, names, fields, force, indentation):
if data is None:
status += 1 # error
continue
storage.save(**data)
if type == "plotterparameter":
declaration = {
"description": data["short_description"],
"plotter": data["plotter"],
"data": data["data"]
}
storage.save(declaration)
else:
storage.save(**data)
available.add(name)
else:
# other workflow with no storage (i.e.: plotterparameter)
......
......@@ -46,6 +46,7 @@ from PIL import Image
from beat.core import plotter
from beat.core import dataformat
from beat.core.plotterparameter import Storage as PPStorage
from . import common
from . import commands
......@@ -259,7 +260,7 @@ def plot_impl(
with open(
os.path.join(
prefix,
common.TYPE_NOSTORAGE["plotterparameter"],
PPStorage.asset_folder,
plotterparameter + ".json",
),
"r",
......
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