You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.8 KiB

from calculate.vars.datavars import Namespace, Variable, ChoiceVariable, ReadonlyVariable, ListVariable, HashVariable, TableVariable, ListVariable
class Simple(Variable):
def get(self):
return "simple value"
class Uselocalsimple(Variable):
def get(self):
return "Using %s" % self.vars.simple.getValue(self)
class Usefullsimple(Variable):
def get(self):
return "Using %s" % self.vars.root.level.simple.getValue(self)
class Badchoice(Variable):
properties = [ChoiceVariable]
class Disks(Variable):
properties = [ListVariable]
def get(self):
return ["/dev/sda1", "/dev/sda2", "/dev/sda3"]
def getComment(self):
mymap = {'/dev/sda1':'SWAP',
'/dev/sda2':'ROOT',
'/dev/sda3':'DATA'}
return [mymap.get(x) for x in self.getValue()]
class SimpleChoice(Variable):
properties = [ChoiceVariable]
def choice(self):
return self.vars.disks.getValue(self)
class CommentChoice(Variable):
properties = [ChoiceVariable]
def choiceComment(self):
return list(zip(self.vars.disks.getValue(),
self.vars.disks.getComment()))
class Version(Variable):
value = "1.0"
class Myshortname(Variable):
value = "CLD"
class Linux(HashVariable):
class Data(HashVariable.Data):
def get(self):
return {
'ver':self.vars.version.getValue(self),
'shortname':self.vars.myshortname.getValue(self)
}
class Test(Variable):
def get(self):
return "my test - %s" % self.vars.ver.getValue(self)
readonly_vars = ['shortname']
hash_vars = ["ver", "shortname"]
class ShortnameTest(Variable):
def get(self):
return "{} test".format(self.vars.linux.shortname.getValue(self))
class Devicelist(Variable):
properties = [ListVariable]
def get(self):
return ["/dev/sda","/dev/sdb"]
class Device(TableVariable):
class Data(TableVariable.Data):
def get(self):
mapData = {'/dev/sda': ["hdd", "Samsung SSD"],
'/dev/sdb': ["flash", "Transcend 64GB"],
'/dev/sdc': ["usbhdd", "WD 1TB"]}
defaultValue = ["hdd", "Unknown"]
return [
{"dev":x,
"type":mapData.get(x,defaultValue)[0],
"name":mapData.get(x,defaultValue)[1]}
for x in self.vars.devicelist.getValue(self)
]
hash_vars = ["dev","type","name"]
readonly_vars = ["name"]
class DeviceChild(Variable):
def get(self):
return self.vars.device[0].type.getValue(self)
class Level3(Namespace):
class MyVar1(Variable):
def get(self):
return "testing"
class Myvar2(Variable):
def get(self):
return "testing2"