major rework
using influxdb structure independed of nicos cache
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from configparser import ConfigParser
|
||||
|
||||
|
||||
class ChartConfig:
|
||||
"""
|
||||
Class that holds the chart section of a configuration file (for an instrument).
|
||||
@@ -6,14 +8,42 @@ class ChartConfig:
|
||||
Attributes :
|
||||
chart_config (Section) : the Section corresponding to the "chart" section in the given configuration file
|
||||
"""
|
||||
|
||||
KEYS = ["cat", "color", "unit", "label"]
|
||||
|
||||
def __init__(self, path):
|
||||
"""
|
||||
Parameters :
|
||||
path (str) : the path to the configuration file
|
||||
"""
|
||||
self.errors = {}
|
||||
self.variables = {}
|
||||
cfgp = ConfigParser(interpolation=None)
|
||||
cfgp.optionxform = str
|
||||
cfgp.read(path)
|
||||
self.chart_config = cfgp["chart"]
|
||||
section = cfgp["chart"]
|
||||
for key, raw_value in section.items():
|
||||
if len(key.split('.')) > 1:
|
||||
self.errors[key] = f'illegal key: {key}'
|
||||
continue
|
||||
arguments = raw_value.split(",")
|
||||
keyword_mode = False
|
||||
config = {'cat': '*'}
|
||||
for i, argument in enumerate(arguments):
|
||||
argname, _, argvalue = argument.rpartition(':')
|
||||
if argname:
|
||||
keyword_mode = True
|
||||
config[argname] = argvalue
|
||||
else:
|
||||
if keyword_mode:
|
||||
self.errors[key] = f"positional arg after keywd arg: {key}={raw_value!r}"
|
||||
else:
|
||||
try:
|
||||
if argvalue:
|
||||
config[self.KEYS[i]] = argvalue
|
||||
except Exception as e:
|
||||
self.errors[key] = f"{e!r} in {key}={raw_value}"
|
||||
self.variables[key] = config
|
||||
|
||||
def get_variable_parameter_config(self, key):
|
||||
"""
|
||||
@@ -27,25 +57,4 @@ class ChartConfig:
|
||||
The different options are in this dict if they are found in the chart section for the given key. Returns None if the key is not in the chart section,
|
||||
or if there is a syntax problem for the given key.
|
||||
"""
|
||||
config = {}
|
||||
positionnal = ["cat", "color", "unit"]
|
||||
if key in self.chart_config.keys():
|
||||
raw_value = self.chart_config[key]
|
||||
|
||||
arguments = raw_value.split(",")
|
||||
keyword_mode = False
|
||||
for i, argument in enumerate(arguments):
|
||||
pieces = argument.split(":")
|
||||
if len(pieces) == 2:
|
||||
keyword_mode = True
|
||||
if pieces[1] != "":
|
||||
config[pieces[0]] = pieces[1]
|
||||
else:
|
||||
if not keyword_mode: #everything is going well
|
||||
if pieces[0] != "":
|
||||
config[positionnal[i]] = pieces[0]
|
||||
else: #we cannot have a positionnal argument after a keyword argument
|
||||
return None
|
||||
return config
|
||||
else:
|
||||
return None
|
||||
return self.variables.get(key)
|
||||
|
||||
Reference in New Issue
Block a user