Commit 796d9a0e authored by Samuel GAIST's avatar Samuel GAIST Committed by Flavio TARSETTI
Browse files

[plotterparameter] Pre-commit cleanup

parent b12f863e
......@@ -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
......@@ -71,7 +68,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, "plotterparameters", name, suffix=".json"
path = path[:-5]
super(Storage, self).__init__(path)
......@@ -122,12 +121,7 @@ class Plotterparameter(object):
JSON decoder.
def __init__(
def __init__(self, prefix, data, plotter_cache=None):
self._name = None = None
self.errors = []
......@@ -170,20 +164,21 @@ class Plotterparameter(object):
self._name = data = Storage(self.prefix, self._name)
if not
self.errors.append(f'Plotterparameter declaration file not found: {data}')
f"Plotterparameter declaration file not found: {data}"
data = # loads data from JSON declaration
# At this point, `data' can be a dictionary or ``None``
# Either way, assign something valid to `'
if data is None: # use the dummy plotterparameter
if data is None: # use the dummy plotterparameter, 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
# this runs basic validation, including JSON loading if required, self.errors = schema.validate("plotterparameter", data)
def _load_plotter(self, plotter_cache):
"""Loads the plotter for the plotterparameter.
Assumes that `' has been calculated.
......@@ -195,7 +190,7 @@ class Plotterparameter(object):
# find the plotter if it wasnt given
if self.plotter is None:
plotter_name =['plotter']
plotter_name =["plotter"]
pl = None
if plotter_name in plotter_cache:
......@@ -210,22 +205,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['data'].items():
for key, val in["data"].items():
self.plotter.clean_parameter(key, val)
except KeyError:
self.errors.append(f"'{key}' isn't a parameter for plotter {}")
f"'{key}' isn't a parameter for plotter {}"
except ValueError:
self.errors.append(f"'{value}' is invalid for parameter {key} of plotter {}")
f"'{val}' is invalid for parameter {key} of plotter {}"
def valid(self):
"""A boolean that indicates if this plotterparameter is valid or not"""
Supports Markdown
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