lpcmanager

Fix options handling : real space resistant parsing. Values surrounded by double quotes in key-value pairs. Dialog stops messing with other columnns. OnChange code overriden in PythonFileCTNMixin so that content of options can add Alaram and StoredValue calls. + various rework in SetOption GetOption to avoid being poisoned by user input
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import re
VARIABLETYPE = ["None", "Static", "Session", "Alarm"]
opt_parser = re.compile(r'(\w+)\s*(?:=\s*"([^"]+)"\s*)?')
def ParseOptions(opts):
class AttrDict(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.__dict__ = self
res = AttrDict(
is_onchange = False,
is_scada = False,
is_static = False,
variable_type_selection = 0,
unit = None,
min = None,
max = None,
precision = None,
subgroup = None,
other = None,
tags = None)
options = re.findall(opt_parser,opts)
for key,value in options:
if value == "":
if key == "onchange":
res.is_onchange = True
elif key in VARIABLETYPE[1:]:
res.variable_type_selection = VARIABLETYPE.index(key)
elif key == "scada":
res.is_scada = True
elif key == "static":
res.is_static = True
else:
if key in ["precision", "min","max"]:
value = int(value)
if key in res:
res[key] = value
else:
raise Exception("Unknown key in options")
return res