update new variables.

master3.3
Mike Hiretsky 12 years ago
parent 53be34cddc
commit eab80435ab

@ -24,6 +24,9 @@ def makePath(dirs,mode=755):
def _(s):
return s
Readonly = "r"
Writeable = "w"
class Variable:
"""
Class of variable. Need for creating calculate utilities variable
@ -47,10 +50,8 @@ class Variable:
metavalue = None
# help information
help = None
# choice for choice type variables
choice = None
# writeable variable
mode = "w"
mode = Writeable
# hidden variable
hide = True
# default value
@ -65,8 +66,6 @@ class Variable:
opt = None
# help for console
help = None
# choice
choice = None
# variable type: string, multichoice, list, number, choiceedit, table
# flag, yesno, password
type = "string"
@ -226,11 +225,16 @@ class Variable:
var.invalidate()
#self.reqVars = []
def isTrue(self,value):
if value.lower() in ('yes','on','true'):
return True
return False
class ReadonlyVariable(Variable):
"""
Alias for readonly variables
"""
mode = "r"
mode = Readonly
class SimpleDataVars:
"""
@ -301,17 +305,21 @@ class DataVars:
_("error") + ": " +str(e)]))
# get all Variable classes from module
# variable of class VariableClAction will be named cl_action
for varModName in filter(lambda x:not x.startswith("_"),
dir(varModule)):
varMod = getattr(varModule,varModName)
if hasattr(varModule,"section"):
section = varModule.section
else:
section = "main"
for varMod in map(lambda x:getattr(varModule,x),
filter(lambda x:not x.startswith("_") and \
not "Variable" in x,
dir(varModule)))+[varModule]:
for classname in \
filter(lambda x:not x in ("Variable","VariableError"),
filter(lambda x:not x in ("ReadonlyVariable",
"Variable","VariableError"),
filter(lambda x:x.startswith("Variable"),
dir(varMod))):
varObj = getattr(varMod,classname)
varName = varObj.getVariableName()
section = varModule.section \
if hasattr(varModule,"section") else "main"
self.allVars[varName] = (section,varObj)
def loadVariable(self,varname):
@ -474,7 +482,7 @@ class DataVars:
except BaseException,e:
while(len(self.requestVariables)):
self.requestVariables.pop()
raise e
raise
def Choice(self, varname):
"""
@ -513,6 +521,12 @@ class DataVars:
else:
return lst
maxlen = len(max(map(self.Get,varobj.source),key=len))
wrongValues = filter(lambda x:type(x[1]) != list,
map(lambda x:(x,self.Get(x)),
varobj.source))
if wrongValues:
raise DataVarsError(
_("Variable %s not contains list")%wrongValues[0][0])
return map(lambda x:list(x),zip(*map(setLen,map(self.Get,varobj.source))))
def __setTable(self,varobj,varvalue):

@ -142,27 +142,30 @@ class VariableOsLinuxName(ReadonlyVariable,Linux):
"""
Full system name
"""
source_variable = "os_linux_shortname"
def get(self):
linuxShortName = self.Get("os_linux_shortname")
linuxShortName = self.Get(self.source_variable)
return self.dictLinuxName.get(linuxShortName,"Linux")
class VariableOsLinuxSubname(ReadonlyVariable,Linux):
"""
Subname of linux (KDE, GNOME, XFCE and etc)
"""
source_variable = "os_linux_shortname"
def get(self):
linuxShortName = self.Get("os_linux_shortname")
linuxShortName = self.Get(self.source_variable)
return self.dictLinuxSubName.get(linuxShortName,"")
class VariableOsLinuxSystem(ReadonlyVariable,Linux):
"""
System of linux (desktop or server)
"""
source_variable = "os_linux_shortname"
def get(self):
shortName = self.Get('os_linux_shortname')
shortName = self.Get(self.source_variable)
return self.dictNameSystem.get(shortName,"")
class VariableOsLinuxVer(ReadonlyVariable,Linux):

Loading…
Cancel
Save