родител
9140335ad5
ревизия
dbf841c689
@ -1,62 +1,68 @@
|
||||
from calculate.variables.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(
|
||||
def import_variables():
|
||||
from calculate.variables.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(
|
||||
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('disks', type=ListType,
|
||||
source=["/dev/sda1", "/dev/sda2", "/dev/sda3"])
|
||||
|
||||
Variable('version', type=FloatType, source='1.0')
|
||||
Variable('version', type=FloatType, source='1.0')
|
||||
|
||||
Variable('my_shortname', type=StringType, source='CLD')
|
||||
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('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(
|
||||
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_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', 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']))
|
||||
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')
|
||||
with Namespace('level_3'):
|
||||
Variable('my_var_1', type=StringType, source='testing')
|
||||
|
||||
Variable('my_var_2', type=StringType, source='testing_2')
|
||||
Variable('my_var_2', type=StringType, source='testing_2')
|
||||
|
@ -1,6 +1,6 @@
|
||||
from calculate.variables.datavars import Variable, StringType, Calculate
|
||||
def import_variables():
|
||||
from calculate.variables.datavars import Variable, StringType, Calculate
|
||||
|
||||
|
||||
Variable('vargetter', type=StringType,
|
||||
source=Calculate(lambda chroot: '{} test'.format(chroot.value),
|
||||
'main.chroot'))
|
||||
Variable('vargetter', type=StringType,
|
||||
source=Calculate(lambda chroot: '{} test'.format(chroot.value),
|
||||
'main.chroot'))
|
||||
|
@ -1,4 +1,4 @@
|
||||
from calculate.variables.datavars import Variable, StringType
|
||||
def import_variables():
|
||||
from calculate.variables.datavars import Variable, StringType
|
||||
|
||||
|
||||
Variable('chroot', type=StringType.readonly, source='/')
|
||||
Variable('chroot', type=StringType.readonly, source='/')
|
||||
|
@ -1,19 +1,17 @@
|
||||
import os
|
||||
from calculate.variables.datavars import Variable, ListType, HashType
|
||||
'''
|
||||
system:
|
||||
env_order -> list
|
||||
env_path -> hash
|
||||
'''
|
||||
def import_variables():
|
||||
'''
|
||||
system:
|
||||
env_order -> list
|
||||
env_path -> hash
|
||||
'''
|
||||
import os
|
||||
from calculate.variables.datavars import Variable, ListType, HashType
|
||||
|
||||
TESTFILES_PATH = os.path.join(os.getcwd(), 'tests/variables/testfiles')
|
||||
# Список мест, где есть calculate.ini файлы.
|
||||
Variable('env_order', type=ListType, source=['system', 'local'])
|
||||
|
||||
TESTFILES_PATH = os.path.join(os.getcwd(), 'tests/variables/testfiles')
|
||||
|
||||
|
||||
# Список мест, где есть calculate.ini файлы.
|
||||
Variable('env_order', type=ListType, source=['system', 'local'])
|
||||
|
||||
# Отображение множества мест, где есть calculate.ini файлы, на пути к ним.
|
||||
Variable('env_path', type=HashType,
|
||||
source={'system': os.path.join(TESTFILES_PATH,
|
||||
'ini_vars/calculate_6.ini')})
|
||||
# Отображение множества мест, где есть calculate.ini файлы, на пути к ним.
|
||||
Variable('env_path', type=HashType,
|
||||
source={'system': os.path.join(TESTFILES_PATH,
|
||||
'ini_vars/calculate_6.ini')})
|
||||
|
@ -1,50 +1,60 @@
|
||||
from calculate.variables.datavars import Namespace, Variable, Dependence,\
|
||||
StringType, HashType, TableType,\
|
||||
ListType, IntegerType, FloatType
|
||||
def import_variables():
|
||||
from calculate.variables.datavars import (
|
||||
Namespace,
|
||||
Variable,
|
||||
Dependence,
|
||||
StringType,
|
||||
HashType,
|
||||
TableType,
|
||||
IntegerType,
|
||||
FloatType
|
||||
)
|
||||
|
||||
with Namespace('linux'):
|
||||
Variable('shortname', source='', type=StringType)
|
||||
with Namespace('linux'):
|
||||
Variable('shortname', source='', type=StringType)
|
||||
|
||||
Variable('ver', source='', type=StringType)
|
||||
Variable('ver', source='', type=StringType)
|
||||
|
||||
Variable('fullname', source='', type=StringType)
|
||||
Variable('fullname', source='', type=StringType)
|
||||
|
||||
Variable('subname', source='', type=StringType)
|
||||
Variable('subname', source='', type=StringType)
|
||||
|
||||
Variable('arch', source='', type=StringType)
|
||||
Variable('arch', source='', type=StringType)
|
||||
|
||||
Variable('test_1', source=12, type=IntegerType)
|
||||
Variable('test_1', source=12, type=IntegerType)
|
||||
|
||||
Variable('test_2', source=1.2, type=FloatType)
|
||||
Variable('test_2', source=1.2, type=FloatType)
|
||||
|
||||
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))
|
||||
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('hashvar', source={'value1': 'test1',
|
||||
'value2': 'test2'}, type=HashType)
|
||||
|
||||
Variable('hashvar_0', source={'value1': 'test1',
|
||||
'value2': 'test2'}, type=HashType)
|
||||
Variable('hashvar_0', source={'value1': 'test1',
|
||||
'value2': 'test2'}, type=HashType)
|
||||
|
||||
Variable('hashvar_1', source={'key1': 'value1',
|
||||
'key2': 'value2'}, type=HashType)
|
||||
Variable('hashvar_1', source={'key1': 'value1',
|
||||
'key2': 'value2'}, type=HashType)
|
||||
|
||||
Variable('hashvar_2', source={'id_1': 1349,
|
||||
'id_2': 1575}, type=HashType)
|
||||
Variable('hashvar_2', source={'id_1': 1349,
|
||||
'id_2': 1575}, type=HashType)
|
||||
|
||||
Variable('calculate', type=StringType,
|
||||
source=Dependence('.hashvar_0',
|
||||
depend=lambda hashvar: "{} {}".format(
|
||||
Variable('calculate', type=StringType,
|
||||
source=Dependence('.hashvar_0',
|
||||
depend=lambda hashvar: "{} {}".format(
|
||||
hashvar.value['value1'],
|
||||
hashvar.value['value2'])))
|
||||
|
||||
Variable('tablevar', type=TableType, source=[{"dev": "/dev/sdb1",
|
||||
"mount": "/"},
|
||||
{"dev": "/dev/sdb2",
|
||||
"mount": "/var/calculate"}])
|
||||
Variable('tablevar', type=TableType, source=[{"dev": "/dev/sdb1",
|
||||
"mount": "/"},
|
||||
{"dev": "/dev/sdb2",
|
||||
"mount": "/var/calculate"}])
|
||||
|
Зареждане…
Reference in new issue