parent
6bfd4c046b
commit
632b88b79f
@ -0,0 +1,62 @@
|
||||
from calculate.vars.alt_datavars import Namespace, Variable, Dependence,\
|
||||
StringType, HashType, TableType,\
|
||||
ListType, FloatType
|
||||
|
||||
|
||||
Variable('simple', type=StringType, source='simple value')
|
||||
|
||||
Variable('use_local_simple', type=StringType,
|
||||
source=Dependence('.simple',
|
||||
depend=lambda simple: 'Using {}'.format(
|
||||
simple.value)))
|
||||
|
||||
Variable('use_full_simple', type=StringType,
|
||||
source=Dependence('level.simple',
|
||||
depend=lambda simple: 'Using {}'.format(
|
||||
simple.value)))
|
||||
|
||||
Variable('disks', type=ListType,
|
||||
source=["/dev/sda1", "/dev/sda2", "/dev/sda3"])
|
||||
|
||||
Variable('version', type=FloatType, source='1.0')
|
||||
|
||||
Variable('my_shortname', type=StringType, source='CLD')
|
||||
|
||||
Variable('linux', type=HashType,
|
||||
source=Dependence('.version', '.my_shortname',
|
||||
depend=lambda version, my_shortname:
|
||||
{'version': version.value,
|
||||
'shortname': my_shortname.value}))
|
||||
|
||||
Variable('shortname_test', type=StringType,
|
||||
source=Dependence('.linux.shortname',
|
||||
depend=lambda shortname: '{} test'.format(
|
||||
shortname.value)))
|
||||
|
||||
Variable('device_list', type=ListType,
|
||||
source=["/dev/sda", "/dev/sdb"])
|
||||
|
||||
|
||||
def get_device_table(device_list):
|
||||
map_data = {'/dev/sda': ["hdd", "Samsung SSD"],
|
||||
'/dev/sdb': ["flash", "Transcend 64GB"],
|
||||
'/dev/sdc': ["usbhdd", "WD 1TB"]}
|
||||
default_value = ["hdd", "Unknown"]
|
||||
print('device_list = {}'.format(device_list.value))
|
||||
return [{"dev": device,
|
||||
"type": map_data.get(device, default_value)[0],
|
||||
"name": map_data.get(device, default_value)[1]}
|
||||
for device in device_list.value]
|
||||
|
||||
|
||||
Variable('device', type=TableType, source=Dependence('.device_list',
|
||||
depend=get_device_table))
|
||||
|
||||
Variable('device_child', type=StringType,
|
||||
source=Dependence('.device',
|
||||
depend=lambda device: device.value[0]['type']))
|
||||
|
||||
with Namespace('level_3'):
|
||||
Variable('my_var_1', type=StringType, source='testing')
|
||||
|
||||
Variable('my_var_2', type=StringType, source='testing_2')
|
@ -0,0 +1,7 @@
|
||||
from calculate.vars.alt_datavars import Variable, StringType, Dependence
|
||||
|
||||
|
||||
Variable('vargetter', type=StringType,
|
||||
source=Dependence('main.chroot',
|
||||
depend=lambda chroot:
|
||||
'{} test'.format(chroot.value)))
|
@ -0,0 +1,5 @@
|
||||
from calculate.vars.alt_datavars import Variable, StringType
|
||||
|
||||
|
||||
Variable('chroot', type=StringType, source='/', readonly=True)
|
||||
print('chroot really created')
|
@ -0,0 +1,36 @@
|
||||
from calculate.vars.alt_datavars import Namespace, Variable, Dependence,\
|
||||
StringType, HashType, TableType
|
||||
|
||||
with Namespace('linux'):
|
||||
Variable('shortname', source='', type=StringType)
|
||||
|
||||
Variable('ver', source='', type=StringType)
|
||||
|
||||
Variable('fullname', source='', type=StringType)
|
||||
|
||||
Variable('subname', source='', type=StringType)
|
||||
|
||||
Variable('arch', source='', type=StringType)
|
||||
|
||||
Variable('test', source='', type=StringType)
|
||||
|
||||
def get_title(subname, fullname, ver):
|
||||
if subname.value:
|
||||
return '{} {} {}'.format(fullname.value, subname.value, ver.value)
|
||||
else:
|
||||
return '{} {}'.format(fullname.value, ver.value)
|
||||
Variable('title', type=StringType,
|
||||
source=Dependence('.subname', '.fullname', '.ver',
|
||||
depend=get_title))
|
||||
|
||||
Variable('hashvar', source={'value1': 'test1',
|
||||
'value2': 'test2'}, type=HashType)
|
||||
|
||||
Variable('calculate', type=StringType,
|
||||
source=lambda hashvar: "{} {}".format(hashvar.value['value1'],
|
||||
hashvar.value['value2']))
|
||||
|
||||
Variable('tablevar', type=TableType, source=[{"dev": "/dev/sdb1",
|
||||
"mount": "/"},
|
||||
{"dev": "/dev/sdb2",
|
||||
"mount": "/var/calculate"}])
|
Loading…
Reference in new issue