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.
120 lines
2.9 KiB
120 lines
2.9 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.get_value(self)
|
|
|
|
|
|
class Usefullsimple(Variable):
|
|
def get(self):
|
|
return "Using %s" % self.vars.root.level.simple.get_value(self)
|
|
|
|
|
|
class Badchoice(Variable):
|
|
properties = [ChoiceVariable]
|
|
|
|
|
|
class Disks(Variable):
|
|
properties = [ListVariable]
|
|
|
|
def get(self):
|
|
return ["/dev/sda1", "/dev/sda2", "/dev/sda3"]
|
|
|
|
def get_comment(self):
|
|
mymap = {'/dev/sda1': 'SWAP',
|
|
'/dev/sda2': 'ROOT',
|
|
'/dev/sda3': 'DATA'}
|
|
return [mymap.get(x) for x in self.get_value()]
|
|
|
|
|
|
class SimpleChoice(Variable):
|
|
properties = [ChoiceVariable]
|
|
|
|
def choice(self):
|
|
return self.vars.disks.get_value(self)
|
|
|
|
|
|
class CommentChoice(Variable):
|
|
properties = [ChoiceVariable]
|
|
|
|
def choice_comment(self):
|
|
return list(zip(self.vars.disks.get_value(),
|
|
self.vars.disks.get_comment()))
|
|
|
|
|
|
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.get_value(self),
|
|
'shortname': self.vars.myshortname.get_value(self)
|
|
}
|
|
|
|
class Test(Variable):
|
|
def get(self):
|
|
return "my test - %s" % self.vars.ver.get_value(self)
|
|
|
|
readonly_vars = ['shortname']
|
|
hash_vars = ["ver", "shortname"]
|
|
|
|
|
|
class ShortnameTest(Variable):
|
|
def get(self):
|
|
return "{} test".format(self.vars.linux.shortname.get_value(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.get_value(self)
|
|
]
|
|
|
|
hash_vars = ["dev", "type", "name"]
|
|
readonly_vars = ["name"]
|
|
|
|
|
|
class DeviceChild(Variable):
|
|
def get(self):
|
|
return self.vars.device[0].type.get_value(self)
|
|
|
|
|
|
class Level3(Namespace):
|
|
class MyVar1(Variable):
|
|
def get(self):
|
|
return "testing"
|
|
|
|
class Myvar2(Variable):
|
|
def get(self):
|
|
return "testing2"
|