lpcmanager

Variable Options : fixed parsing, add On Load fix
som6
2020-11-12, Edouard Tisserant
fecb8381e105
Variable Options : fixed parsing, add On Load fix
- fixed parsing to deal with dblquotes and old bugs better, use intermediate representation once parsed, and add function to generate options string from that representation,
- add On Load fix to be backward compatible with previous options syntax and onchange column
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from OptionsParsing import ParseOptions, GenOptions
@staticmethod
def GetVarOnChangeContent(var):
"""
Function to overide the way PythonFileCTNMixin access OnChange column when
generating python code
"""
opts = ParseOptions(var.getopts())
if opts.is_onchange:
new_onchange = [
onchange.strip() for onchange in var.getonchange().split(',')]
if opts.variable_type_selection == 1 : # "Static"
new_onchange += ["StoredValue"]
elif opts.variable_type_selection == 3 : # "Alarm"
new_onchange += ["Alarm"]
return ','.join(new_onchange)
return var.getonchange()
def FixOptions(self):
"""
Function to be called at the end of PythonFileCTNMixin.__init__()
"""
for var in self.CodeFile.variables.variable:
onchanges = [
onchange.strip() for onchange in var.getonchange().split(',')]
opts = ParseOptions(var.getopts())
for unwanted in ["Alarm", "StoredValue"]:
if unwanted in onchanges:
opts.is_onchange = True
onchanges.remove(unwanted)
var.setonchange(','.join(onchanges))
var.setopts(GenOptions(opts))