|
|
|
@ -18,15 +18,75 @@
|
|
|
|
|
from soaplib.serializers.primitive import String, Integer, Boolean, Any
|
|
|
|
|
from soaplib.serializers.clazz import Array, ClassSerializer
|
|
|
|
|
from soaplib.service import rpc
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
|
|
|
setLocalTranslate('calculate_api',sys.modules[__name__])
|
|
|
|
|
|
|
|
|
|
################# API ########################
|
|
|
|
|
class ChoiceValue(ClassSerializer):
|
|
|
|
|
class DataVarsSerializer(ClassSerializer):
|
|
|
|
|
"""Serializer for datavars types"""
|
|
|
|
|
|
|
|
|
|
def elementByType(self,typeobj):
|
|
|
|
|
"""Get element by variable type, given for table or not"""
|
|
|
|
|
elementMap = {'table':'table',
|
|
|
|
|
"string":"input",
|
|
|
|
|
"bool":"check",
|
|
|
|
|
"boolauto":"check_tristate",
|
|
|
|
|
"choice":"combo",
|
|
|
|
|
"choiceedit":"comboEdit",
|
|
|
|
|
"choiceedit-list":"multichoice_add",
|
|
|
|
|
"choice-list":"multichoice",
|
|
|
|
|
"bool-list":"multichoice",
|
|
|
|
|
"list":"multichoice_add",
|
|
|
|
|
"password":"password"}
|
|
|
|
|
return elementMap.get(typeobj,'input')
|
|
|
|
|
|
|
|
|
|
def arrayString(self,value):
|
|
|
|
|
print "arrayString",value.__repr__()
|
|
|
|
|
if type(value) == (list,tuple):
|
|
|
|
|
return [""]+value
|
|
|
|
|
else:
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def arrayArrayString(self,value):
|
|
|
|
|
print "arrayArrayString",value.__repr__()
|
|
|
|
|
if type(value) in (list,tuple):
|
|
|
|
|
return map(self.arrayString,value)
|
|
|
|
|
else:
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def getChoice(self,varObj):
|
|
|
|
|
if "choice" in varObj.type or "file" in varObj.type:
|
|
|
|
|
choice,comments = varObj.parent.ChoiceAndComments(varObj.name)
|
|
|
|
|
return self.arrayString(choice),self.arrayString(comments)
|
|
|
|
|
else:
|
|
|
|
|
return (None,None)
|
|
|
|
|
|
|
|
|
|
class ChoiceValue(DataVarsSerializer):
|
|
|
|
|
typefield = String
|
|
|
|
|
values = Array(String)
|
|
|
|
|
comments = Array(String)
|
|
|
|
|
onChanged = Array(String)
|
|
|
|
|
|
|
|
|
|
class Table(ClassSerializer):
|
|
|
|
|
def __init__(self,dv=None,varObj=None,**kwargs):
|
|
|
|
|
if dv:
|
|
|
|
|
super(ChoiceValue,self).__init__()
|
|
|
|
|
self.values, self.comments = self.getChoice(varObj)
|
|
|
|
|
if varObj.mode == 'w':
|
|
|
|
|
self.typefield = varObj.element or \
|
|
|
|
|
self.elementByType(varObj.type)
|
|
|
|
|
else:
|
|
|
|
|
self.typefield = "text"
|
|
|
|
|
else:
|
|
|
|
|
super(ChoiceValue,self).__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
def elementByType(self,typeobj):
|
|
|
|
|
"""Get element by variable type, given for table or not"""
|
|
|
|
|
return DataVarsSerializer.elementByType(self,
|
|
|
|
|
typeobj.replace("-list","").replace("list",""))
|
|
|
|
|
|
|
|
|
|
class Table(DataVarsSerializer):
|
|
|
|
|
head = Array(String)
|
|
|
|
|
fields = Array(String) # name fields in params object
|
|
|
|
|
body = Array(Array(String))
|
|
|
|
@ -34,37 +94,175 @@ class Table(ClassSerializer):
|
|
|
|
|
onClick = String
|
|
|
|
|
addAction = String
|
|
|
|
|
|
|
|
|
|
class Option(ClassSerializer):
|
|
|
|
|
def __init__(self,dv=None,varObj=None,head=None,body=None,values=None):
|
|
|
|
|
super(Table,self).__init__()
|
|
|
|
|
if dv:
|
|
|
|
|
self.head = []
|
|
|
|
|
self.body = []
|
|
|
|
|
self.values = []
|
|
|
|
|
# get information about all table columns
|
|
|
|
|
self.writable = True
|
|
|
|
|
for i,col in enumerate(varObj.source):
|
|
|
|
|
# get columns variable obj
|
|
|
|
|
varSource = dv.getInfo(col)
|
|
|
|
|
# invalidate columns vars for uncompatible table
|
|
|
|
|
if varSource.uncompatible():
|
|
|
|
|
dv.Invalidate(col,onlySet=True)
|
|
|
|
|
# header label
|
|
|
|
|
self.head.append(varSource.label or varSource.name)
|
|
|
|
|
# if column writable then add ChoiceValue info
|
|
|
|
|
if varSource.mode == 'w' or i == 0:
|
|
|
|
|
self.values.append(ChoiceValue(dv,varSource))
|
|
|
|
|
if varSource.mode == 'r' and i == 0:
|
|
|
|
|
self.writable = False
|
|
|
|
|
# get table body
|
|
|
|
|
# empty value at start add for fix data transfer
|
|
|
|
|
self.body = self.arrayArrayString(dv.Get(varObj.name))
|
|
|
|
|
else:
|
|
|
|
|
self.head = head
|
|
|
|
|
self.body = body
|
|
|
|
|
self.values = values
|
|
|
|
|
|
|
|
|
|
class Option(DataVarsSerializer):
|
|
|
|
|
shortopt = String
|
|
|
|
|
longopt = String
|
|
|
|
|
metavalue = String
|
|
|
|
|
help = String
|
|
|
|
|
|
|
|
|
|
def __init__(self,optlist,metaval,helpval):
|
|
|
|
|
super(Option,self).__init__()
|
|
|
|
|
self.help = helpval
|
|
|
|
|
self.metavalue = metaval
|
|
|
|
|
for val in optlist:
|
|
|
|
|
if val.startswith('--'):
|
|
|
|
|
self.longopt=val
|
|
|
|
|
else:
|
|
|
|
|
self.shortopt=val
|
|
|
|
|
|
|
|
|
|
class Field(ClassSerializer):
|
|
|
|
|
name = String
|
|
|
|
|
label = String
|
|
|
|
|
type = String
|
|
|
|
|
opt = Option
|
|
|
|
|
help = String
|
|
|
|
|
element = String
|
|
|
|
|
choice = Array(String)
|
|
|
|
|
listvalue = Array(String)
|
|
|
|
|
default = Boolean
|
|
|
|
|
value = String
|
|
|
|
|
tablevalue = Table
|
|
|
|
|
uncompatible = String
|
|
|
|
|
comments = Array(String)
|
|
|
|
|
|
|
|
|
|
class GroupField(ClassSerializer):
|
|
|
|
|
class Field(DataVarsSerializer):
|
|
|
|
|
name = String # varname from Datavars
|
|
|
|
|
label = String # label for GUI
|
|
|
|
|
type = String # data type of variable
|
|
|
|
|
opt = Option # opt for cmdline
|
|
|
|
|
help = String # help for cmdline (GUI?)
|
|
|
|
|
element = String # type element
|
|
|
|
|
choice = Array(String) # value (combobox,comboedit)
|
|
|
|
|
listvalue = Array(String) # current listvalue
|
|
|
|
|
default = Boolean # default value or False
|
|
|
|
|
value = String # current value
|
|
|
|
|
tablevalue = Table # current table value
|
|
|
|
|
uncompatible = String # message for uncompatibility variable
|
|
|
|
|
comments = Array(String) # comments for choice
|
|
|
|
|
|
|
|
|
|
def __init__(self,dv=None,varObj=None,expert=False,**kwargs):
|
|
|
|
|
if dv:
|
|
|
|
|
super(Field,self).__init__()
|
|
|
|
|
self.name = varObj.name
|
|
|
|
|
self.label = varObj.label or varObj.name
|
|
|
|
|
self.type = varObj.type
|
|
|
|
|
if varObj.opt:
|
|
|
|
|
self.opt = Option(varObj.opt,varObj.metavalue,varObj.help)
|
|
|
|
|
self.help = varObj.help
|
|
|
|
|
self.element = varObj.element or \
|
|
|
|
|
self.elementByType(self.type)
|
|
|
|
|
self.uncompatible = dv.Uncompatible(varObj.name)
|
|
|
|
|
if self.uncompatible:
|
|
|
|
|
dv.Invalidate(varObj.name,onlySet=True)
|
|
|
|
|
if expert:
|
|
|
|
|
self.default = not varObj.wasSet
|
|
|
|
|
if self.type == "table":
|
|
|
|
|
self.tablevalue = Table(dv=dv,varObj=varObj)
|
|
|
|
|
if self.tablevalue.writable:
|
|
|
|
|
self.type = "writable"
|
|
|
|
|
else:
|
|
|
|
|
value = dv.Get(varObj.name)
|
|
|
|
|
if type(value) == list:
|
|
|
|
|
self.listvalue = self.arrayString(value)
|
|
|
|
|
else:
|
|
|
|
|
self.value = value
|
|
|
|
|
#if self.value:
|
|
|
|
|
# self.default = self.value
|
|
|
|
|
self.choice, self.comments = self.getChoice(varObj)
|
|
|
|
|
else:
|
|
|
|
|
super(Field,self).__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
class GroupField(DataVarsSerializer):
|
|
|
|
|
name = String
|
|
|
|
|
fields = Array(Field)
|
|
|
|
|
prevlabel = String
|
|
|
|
|
nextlabel = String
|
|
|
|
|
prevlabel = String
|
|
|
|
|
last = Boolean
|
|
|
|
|
|
|
|
|
|
def __init__(self,name="",fields=[],prevlabel="",
|
|
|
|
|
nextlabel="",last=False,dv=None,info=None,
|
|
|
|
|
expert=False):
|
|
|
|
|
super(GroupField,self).__init__()
|
|
|
|
|
self.last = last
|
|
|
|
|
if dv:
|
|
|
|
|
self.name = info['name']
|
|
|
|
|
self.nextlabel = info['next_label']
|
|
|
|
|
self.prevlabel = _("Previous")
|
|
|
|
|
self.fields = []
|
|
|
|
|
|
|
|
|
|
for varname in info['normal']:
|
|
|
|
|
print "Varname",varname
|
|
|
|
|
self.fields.append(Field(dv=dv,varObj=dv.getInfo(varname)))
|
|
|
|
|
|
|
|
|
|
if info['expert']:
|
|
|
|
|
for varname in info['expert']:
|
|
|
|
|
if expert == True or \
|
|
|
|
|
expert == None and dv.getInfo(varname).wasSet:
|
|
|
|
|
self.fields.append(Field(name = "expert",
|
|
|
|
|
element = "expert",
|
|
|
|
|
label=info['expert_label'],
|
|
|
|
|
value="open"))
|
|
|
|
|
for varname in info['expert']:
|
|
|
|
|
self.fields.append(Field(dv=dv,expert=True,
|
|
|
|
|
varObj=dv.getInfo(varname)))
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
if expert == False:
|
|
|
|
|
for varname in info['expert']:
|
|
|
|
|
dv.Invalidate(varname,True)
|
|
|
|
|
self.fields.append(Field(name = "expert",
|
|
|
|
|
element = "expert",
|
|
|
|
|
label=info['expert_label'],
|
|
|
|
|
value="close"))
|
|
|
|
|
else:
|
|
|
|
|
self.name = name
|
|
|
|
|
self.fields = fields
|
|
|
|
|
self.nextlabel = nextlabel
|
|
|
|
|
|
|
|
|
|
class ViewInfo(ClassSerializer):
|
|
|
|
|
class ViewInfo(DataVarsSerializer):
|
|
|
|
|
groups = Array(GroupField)
|
|
|
|
|
|
|
|
|
|
def __init__(self,datavars=None,step=None,expert=None,allsteps=False,groups=[]):
|
|
|
|
|
super(ViewInfo,self).__init__()
|
|
|
|
|
if datavars:
|
|
|
|
|
self.groups = []
|
|
|
|
|
varGroups = datavars.getGroups()
|
|
|
|
|
lastGroup = len(varGroups)-1
|
|
|
|
|
# interate all vars group
|
|
|
|
|
if step in(0,None) or allsteps:
|
|
|
|
|
self.groups.append(self.stepGroup(varGroups))
|
|
|
|
|
for i, groupInfo in enumerate(varGroups):
|
|
|
|
|
if step is None or step == i:
|
|
|
|
|
self.groups.append(GroupField(dv=datavars,info=groupInfo,
|
|
|
|
|
last=(lastGroup==i),expert=expert))
|
|
|
|
|
else:
|
|
|
|
|
self.groups = groups
|
|
|
|
|
|
|
|
|
|
def stepGroup(self,groupInfo):
|
|
|
|
|
"""Step group"""
|
|
|
|
|
return GroupField(fields=[
|
|
|
|
|
Field(name = "Steps",
|
|
|
|
|
element = "table",
|
|
|
|
|
type = 'steps',
|
|
|
|
|
tablevalue = Table(
|
|
|
|
|
head = [i['name'] for i in groupInfo],
|
|
|
|
|
body = [list(i['normal'])+[""]+list(i['expert'])
|
|
|
|
|
for i in groupInfo]))])
|
|
|
|
|
|
|
|
|
|
#element = ['table', 'radio', 'combo', 'comboEdit', 'multichoice', \
|
|
|
|
|
#'multichoice_add', 'check', 'check_tristate', 'expert', 'input']
|
|
|
|
@ -107,160 +305,6 @@ class ReturnProgress(ClassSerializer):
|
|
|
|
|
class Frame(ClassSerializer):
|
|
|
|
|
values = Array (Message)
|
|
|
|
|
|
|
|
|
|
def getViewForVariables(datavars,step=None,expert=None):
|
|
|
|
|
"""
|
|
|
|
|
Get view by DataVars
|
|
|
|
|
"""
|
|
|
|
|
def elementByType(typeobj,fortable=False):
|
|
|
|
|
"""Get element by variable type, given for table or not"""
|
|
|
|
|
if fortable:
|
|
|
|
|
typeobj = typeobj.replace("-list","").replace("list","")
|
|
|
|
|
elementMap = {'table':'table',
|
|
|
|
|
"string":"input",
|
|
|
|
|
"bool":"check",
|
|
|
|
|
"choice":"combo",
|
|
|
|
|
"choiceedit":"comboEdit",
|
|
|
|
|
"choiceedit-list":"multichoice_add",
|
|
|
|
|
"choice-list":"multichoice",
|
|
|
|
|
"bool-list":"multichoice",
|
|
|
|
|
"list":"multichoice_add",
|
|
|
|
|
"password":"password"}
|
|
|
|
|
return elementMap.get(typeobj,'input')
|
|
|
|
|
|
|
|
|
|
view = ViewInfo(groups = [])
|
|
|
|
|
groups = datavars.getGroups()
|
|
|
|
|
lastGroup = len(groups)-1
|
|
|
|
|
# interate all vars group
|
|
|
|
|
for i, groupInfo in enumerate(groups):
|
|
|
|
|
groupname = groupInfo['name']
|
|
|
|
|
normalvariables = groupInfo['normal']
|
|
|
|
|
expertvariables = groupInfo['expert']
|
|
|
|
|
nextbutton = groupInfo['next_label']
|
|
|
|
|
# if not specified step or this selected step
|
|
|
|
|
if step is None or step == i:
|
|
|
|
|
group = GroupField(name=groupname,nextlabel=nextbutton)
|
|
|
|
|
group.fields = []
|
|
|
|
|
group.last = lastGroup == i
|
|
|
|
|
# append steps field on first step or on all vars
|
|
|
|
|
if step in(0,None):
|
|
|
|
|
group.fields.append(Field(
|
|
|
|
|
name = "Steps",
|
|
|
|
|
element = "table",
|
|
|
|
|
type = 'steps',
|
|
|
|
|
tablevalue = Table(
|
|
|
|
|
head = [i['name'] for i in groups],
|
|
|
|
|
body = [list(i['normal'])+[""]+list(i['expert'])
|
|
|
|
|
for i in groups])))
|
|
|
|
|
# iterate normal and expert variables
|
|
|
|
|
for variables in (normalvariables,expertvariables):
|
|
|
|
|
# if current non-empty expert variables
|
|
|
|
|
if variables and variables == expertvariables:
|
|
|
|
|
# search all expert variables
|
|
|
|
|
print "Expert",expert
|
|
|
|
|
for varname in expertvariables:
|
|
|
|
|
if expert == True: break
|
|
|
|
|
if expert == None and \
|
|
|
|
|
datavars.getInfo(varname).wasSet:
|
|
|
|
|
break
|
|
|
|
|
# if request not for expert variables
|
|
|
|
|
# or neither expert variable was set
|
|
|
|
|
else:
|
|
|
|
|
# if was close expert vars invalidate all expert vars
|
|
|
|
|
if expert == False:
|
|
|
|
|
for varname in expertvariables:
|
|
|
|
|
datavars.Invalidate(varname,True)
|
|
|
|
|
# non display expert variables
|
|
|
|
|
variables = ()
|
|
|
|
|
# add expert label
|
|
|
|
|
group.fields.append(Field(
|
|
|
|
|
name = "expert",
|
|
|
|
|
element = "expert",
|
|
|
|
|
value="open" if variables else "close"))
|
|
|
|
|
# iterate variables (normal or variables)
|
|
|
|
|
for varname in variables:
|
|
|
|
|
# get variable object
|
|
|
|
|
varObj = datavars.getInfo(varname)
|
|
|
|
|
table = None
|
|
|
|
|
# invalidate uncompatible variables
|
|
|
|
|
if varObj.uncompatible():
|
|
|
|
|
datavars.Invalidate(varname,onlySet=True)
|
|
|
|
|
# table variable
|
|
|
|
|
if varObj.type == "table":
|
|
|
|
|
table = Table(head=[],body=[], values = [])
|
|
|
|
|
# get information about all table columns
|
|
|
|
|
for i,col in enumerate(varObj.source):
|
|
|
|
|
# get columns variable obj
|
|
|
|
|
varSource = datavars.getInfo(col)
|
|
|
|
|
# invalidate columns vars for uncompatible table
|
|
|
|
|
if varSource.uncompatible():
|
|
|
|
|
datavars.Invalidate(col,onlySet=True)
|
|
|
|
|
# header label
|
|
|
|
|
table.head.append(varSource.label or
|
|
|
|
|
varSource.name)
|
|
|
|
|
# if column writable then add ChoiceValue info
|
|
|
|
|
if varSource.mode == 'w':
|
|
|
|
|
table.values.append(ChoiceValue(
|
|
|
|
|
typefield = elementByType(varSource.type,
|
|
|
|
|
fortable=True),
|
|
|
|
|
values = [""]+list(datavars.Choice(col))))
|
|
|
|
|
# if readonly column - first, set this fild to text
|
|
|
|
|
elif i == 0:
|
|
|
|
|
table.values.append(ChoiceValue(
|
|
|
|
|
typefield = "text",
|
|
|
|
|
values = datavars.Choice(col)))
|
|
|
|
|
# get table body
|
|
|
|
|
# empty value at start add for fix data transfer
|
|
|
|
|
value = map(lambda x:[""]+x,datavars.Get(varname))
|
|
|
|
|
table.body = value
|
|
|
|
|
# get variable value
|
|
|
|
|
value = datavars.Get(varname)
|
|
|
|
|
# list value transfer via 'listvalue'
|
|
|
|
|
listvalue = [""]+value \
|
|
|
|
|
if type(value) == list and varObj.type != 'table' \
|
|
|
|
|
else None
|
|
|
|
|
# not list value transfer via 'value'
|
|
|
|
|
value = str(value) if type(value) != list else None
|
|
|
|
|
# detect writable index table or readonly index
|
|
|
|
|
if varObj.type == "table":
|
|
|
|
|
if datavars.getInfo(varObj.source[0]).mode == 'w':
|
|
|
|
|
fieldtype = "writable"
|
|
|
|
|
else:
|
|
|
|
|
fieldtype = "table"
|
|
|
|
|
# set type by variable
|
|
|
|
|
else:
|
|
|
|
|
fieldtype = varObj.type
|
|
|
|
|
# if choice variable get value from datavars
|
|
|
|
|
if "choice" in fieldtype or "file" in fieldtype:
|
|
|
|
|
choice,comments = datavars.ChoiceAndComments(varname)
|
|
|
|
|
choice = [""]+list(choice)
|
|
|
|
|
if comments:
|
|
|
|
|
comments = [""]+list(comments)
|
|
|
|
|
else:
|
|
|
|
|
choice = None
|
|
|
|
|
comments = None
|
|
|
|
|
# exclude selected values from choice (multivalue)
|
|
|
|
|
if choice and listvalue:
|
|
|
|
|
choice = list(set(choice) - set(listvalue))
|
|
|
|
|
# create variable field
|
|
|
|
|
group.fields.append(Field(
|
|
|
|
|
name = varname,
|
|
|
|
|
label = varObj.label or varname,
|
|
|
|
|
type = fieldtype,
|
|
|
|
|
choice = choice,
|
|
|
|
|
comments = comments,
|
|
|
|
|
uncompatible = datavars.Uncompatible(varname),
|
|
|
|
|
default = value,
|
|
|
|
|
value = value,
|
|
|
|
|
listvalue = listvalue,
|
|
|
|
|
opt = None,#",".join(varObj.opt),
|
|
|
|
|
help = varObj.help,
|
|
|
|
|
metavalue = varObj.metavalue,
|
|
|
|
|
element = varObj.element or \
|
|
|
|
|
elementByType(varObj.type),
|
|
|
|
|
tablevalue = table))
|
|
|
|
|
view.groups.append(group)
|
|
|
|
|
return view
|
|
|
|
|
|
|
|
|
|
from decorators import Dec
|
|
|
|
|
import pickle, os
|
|
|
|
|
# get and send client messages
|
|
|
|
|