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

[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__(
self,
prefix,
data,
plotter_cache=None,
):
def __init__(self, prefix, data, plotter_cache=None):
self._name = None
self.storage = None
self.errors = []
......@@ -170,20 +164,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 +190,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 +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 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"""
......
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