feat: default value for a calculated variable with an unknown optional variable
This commit is contained in:
parent
af473317c3
commit
7f62590085
27 changed files with 273 additions and 35 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
from tiramisu import owners
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rougail import RougailConfig
|
from rougail import RougailConfig
|
||||||
|
|
||||||
|
|
@ -12,36 +13,49 @@ def get_funcs():
|
||||||
return [str(test) for test in sorted((Path(__file__).parent.parent.parent / 'funcs').iterdir()) if test.name.endswith('.py')]
|
return [str(test) for test in sorted((Path(__file__).parent.parent.parent / 'funcs').iterdir()) if test.name.endswith('.py')]
|
||||||
|
|
||||||
|
|
||||||
def get_rougail_config(test_dir, namespace=False):
|
def get_rougail_config(test_dir, namespace=False, relative_to=None):
|
||||||
rougailconfig = RougailConfig
|
rougailconfig = RougailConfig
|
||||||
rougailconfig['functions_files'] = get_funcs()
|
rougailconfig['functions_files'] = get_funcs()
|
||||||
dirs = [str(test_dir / 'rougail')]
|
if relative_to:
|
||||||
|
dirs = [str((test_dir / 'rougail').relative_to(relative_to, walk_up=True))]
|
||||||
|
else:
|
||||||
|
dirs = [str((test_dir / 'rougail'))]
|
||||||
subfolder = test_dir / 'rougail2'
|
subfolder = test_dir / 'rougail2'
|
||||||
if subfolder.is_dir():
|
if subfolder.is_dir():
|
||||||
dirs.append(str(subfolder))
|
if relative_to:
|
||||||
rougailconfig['main_dictionaries'] = dirs
|
dirs.append(str(subfolder.relative_to(relative_to, walk_up=True)))
|
||||||
|
else:
|
||||||
|
dirs.append(str(subfolder))
|
||||||
|
rougailconfig['main_structural_directories'] = dirs
|
||||||
if namespace:
|
if namespace:
|
||||||
rougailconfig['main_namespace'] = 'Rougail'
|
|
||||||
if (test_dir / 'force_no_namespace').is_file():
|
if (test_dir / 'force_no_namespace').is_file():
|
||||||
return None
|
return None
|
||||||
|
rougailconfig['main_namespace'] = 'Rougail'
|
||||||
else:
|
else:
|
||||||
rougailconfig['main_namespace'] = None
|
|
||||||
if (test_dir / 'force_namespace').is_file():
|
if (test_dir / 'force_namespace').is_file():
|
||||||
return None
|
return None
|
||||||
extra_dictionaries = {}
|
rougailconfig['main_namespace'] = None
|
||||||
|
if (test_dir / 'default_structural_format_version').is_file():
|
||||||
|
rougailconfig["default_structural_format_version"] = "1.1"
|
||||||
|
else:
|
||||||
|
rougailconfig["default_structural_format_version"] = None
|
||||||
|
extra_namespaces = {}
|
||||||
extras = list(test_dir.iterdir())
|
extras = list(test_dir.iterdir())
|
||||||
extras.sort()
|
extras.sort()
|
||||||
for extra in extras:
|
for extra in extras:
|
||||||
if extra.name in ['rougail', 'rougail2', 'file']:
|
if extra.name in ['rougail', 'rougail2', 'file']:
|
||||||
continue
|
continue
|
||||||
if extra.is_dir():
|
if extra.is_dir():
|
||||||
extra_dictionaries[extra.name] = [str(extra)]
|
if relative_to:
|
||||||
if extra_dictionaries:
|
extra_namespaces[extra.name] = [str(extra.relative_to(relative_to, walk_up=True))]
|
||||||
|
else:
|
||||||
|
extra_namespaces[extra.name] = [str(extra)]
|
||||||
|
if extra_namespaces:
|
||||||
if not namespace:
|
if not namespace:
|
||||||
return None
|
return None
|
||||||
rougailconfig['extra_dictionaries'] = extra_dictionaries
|
rougailconfig['extra_namespaces'] = extra_namespaces
|
||||||
else:
|
else:
|
||||||
rougailconfig['extra_dictionaries'] = {}
|
rougailconfig['extra_namespaces'] = {}
|
||||||
rougailconfig['custom_types']['custom'] = CustomOption
|
rougailconfig['custom_types']['custom'] = CustomOption
|
||||||
# rougailconfig['tiramisu_cache'] = "cache.py"
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
||||||
return rougailconfig
|
return rougailconfig
|
||||||
|
|
@ -56,7 +70,7 @@ def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unre
|
||||||
uconfig = config
|
uconfig = config
|
||||||
excludes = []
|
excludes = []
|
||||||
get_excludes(uconfig, excludes)
|
get_excludes(uconfig, excludes)
|
||||||
config.property.read_only()
|
config.property.read_write()
|
||||||
root_config = uconfig
|
root_config = uconfig
|
||||||
if level == 'all':
|
if level == 'all':
|
||||||
only = False
|
only = False
|
||||||
|
|
@ -111,15 +125,15 @@ def get_value(variable, index, excludes, config, use_unrestraint):
|
||||||
elif variable.type() == 'choice':
|
elif variable.type() == 'choice':
|
||||||
tests = variable.value.list()
|
tests = variable.value.list()
|
||||||
elif variable.type() == 'network address':
|
elif variable.type() == 'network address':
|
||||||
if variable.extra('_cidr'):
|
if variable.extra('cidr'):
|
||||||
tests = ['192.168.1.0/24', '10.0.0.0/24']
|
tests = ['192.168.1.6/32', '10.0.0.0/24']
|
||||||
else:
|
else:
|
||||||
tests = ['192.168.1.0', '10.0.0.0']
|
tests = ['192.168.1.0', '10.0.0.0']
|
||||||
elif variable.type() == 'netmask address':
|
elif variable.type() == 'netmask address':
|
||||||
tests = ['255.255.255.0', '255.255.0.0']
|
tests = ['255.255.255.0', '255.255.0.0']
|
||||||
elif variable.type() == 'IP':
|
elif variable.type() == 'IP':
|
||||||
if variable.extra('_cidr'):
|
if variable.extra('cidr'):
|
||||||
tests = ['192.168.1.6/32', '10.0.10.0/24']
|
tests = ['192.168.1.6/24', '10.0.10.0/24']
|
||||||
else:
|
else:
|
||||||
tests = ['192.168.1.6', '10.0.10.10']
|
tests = ['192.168.1.6', '10.0.10.10']
|
||||||
elif variable.type() == 'email address':
|
elif variable.type() == 'email address':
|
||||||
|
|
@ -137,16 +151,25 @@ def get_value(variable, index, excludes, config, use_unrestraint):
|
||||||
tests = ['string1', 'string2', 'string3']
|
tests = ['string1', 'string2', 'string3']
|
||||||
if not variable.ismulti():
|
if not variable.ismulti():
|
||||||
tests = tests[0]
|
tests = tests[0]
|
||||||
|
elif variable.isleader() and variable.owner.get() == owners.default:
|
||||||
|
len_leader = len(variable.value.get())
|
||||||
|
if len_leader:
|
||||||
|
for idx in range(len_leader - 1, -1, -1):
|
||||||
|
variable.value.pop(idx)
|
||||||
elif index is not None and variable.isfollower() and variable.issubmulti() is False:
|
elif index is not None and variable.isfollower() and variable.issubmulti() is False:
|
||||||
if len(tests) > index:
|
if len(tests) > index:
|
||||||
tests = tests[index]
|
tests = tests[index]
|
||||||
else:
|
else:
|
||||||
tests = tests[0]
|
tests = tests[0]
|
||||||
if not use_unrestraint:
|
# if not use_unrestraint:
|
||||||
config.property.read_write()
|
# config.property.read_write()
|
||||||
variable.value.set(tests)
|
variable.value.set(tests)
|
||||||
if not use_unrestraint:
|
if variable.index() is None:
|
||||||
config.property.read_only()
|
variable.information.set('loaded_from', 'loaded from rougail-test')
|
||||||
|
else:
|
||||||
|
no_index_variable = config.option(variable.path()).information.set(f'loaded_from_{index}', 'loaded from rougail-test')
|
||||||
|
# if not use_unrestraint:
|
||||||
|
# config.property.read_only()
|
||||||
# if tests == None:
|
# if tests == None:
|
||||||
# tests = ""
|
# tests = ""
|
||||||
if index is not None and variable.isleader():
|
if index is not None and variable.isleader():
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: a first variable
|
||||||
|
multi: true
|
||||||
|
type: domainname
|
||||||
|
params:
|
||||||
|
allow_ip: true
|
||||||
|
|
||||||
|
var2:
|
||||||
|
description: a second variable
|
||||||
|
multi: true
|
||||||
|
type: domainname
|
||||||
|
default:
|
||||||
|
type: variable
|
||||||
|
variable: _.var1
|
||||||
|
|
@ -8,5 +8,5 @@ var:
|
||||||
{% for n in trange(0, 10) %}
|
{% for n in trange(0, 10) %}
|
||||||
{{ n }}
|
{{ n }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
return_type: 'number'
|
return_type: 'integer'
|
||||||
description: choices is 0 to 9
|
description: choices is 0 to 9
|
||||||
|
|
|
||||||
18
structures/00_6integer/rougail/00-base.yml
Normal file
18
structures/00_6integer/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
version: '1.1'
|
||||||
|
var1: 0 # the first variable
|
||||||
|
var2:
|
||||||
|
description: the second variable
|
||||||
|
default: 0
|
||||||
|
var3:
|
||||||
|
description: the third variable
|
||||||
|
type: integer
|
||||||
|
default: 0
|
||||||
|
var4: 10 # this forth variable
|
||||||
|
var5:
|
||||||
|
description: the fifth variable
|
||||||
|
default: 10
|
||||||
|
var6:
|
||||||
|
description: the sixth variable
|
||||||
|
type: integer
|
||||||
|
default: 10
|
||||||
23
structures/00_6ip/rougail/00-base.yml
Normal file
23
structures/00_6ip/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: an IP
|
||||||
|
type: ip
|
||||||
|
default: 1.1.1.1
|
||||||
|
|
||||||
|
var2:
|
||||||
|
description: an IP in CIDR format
|
||||||
|
type: ip
|
||||||
|
params:
|
||||||
|
cidr: true
|
||||||
|
default: 1.1.1.1/24
|
||||||
|
examples:
|
||||||
|
- 192.168.0.128/25
|
||||||
|
|
||||||
|
var3:
|
||||||
|
description: an IP in CIDR format with obsolete CIDR type
|
||||||
|
type: cidr
|
||||||
|
default: 1.1.1.1/24
|
||||||
|
...
|
||||||
21
structures/00_6network/rougail/00-base.yml
Normal file
21
structures/00_6network/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: an network
|
||||||
|
type: network
|
||||||
|
default: 1.1.1.0
|
||||||
|
|
||||||
|
var2:
|
||||||
|
description: an network in CIDR format
|
||||||
|
type: network
|
||||||
|
params:
|
||||||
|
cidr: true
|
||||||
|
default: 1.1.1.0/24
|
||||||
|
|
||||||
|
var3:
|
||||||
|
description: an network in CIDR format with obsolete CIDR type
|
||||||
|
type: network_cidr
|
||||||
|
default: 1.1.1.0/24
|
||||||
|
...
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
my_variable:
|
||||||
|
default: val1
|
||||||
|
my_calculated_variable:
|
||||||
|
multi: true
|
||||||
|
default:
|
||||||
|
- variable: _.my_variable
|
||||||
|
optional: true
|
||||||
|
- variable: _.my_variable_unexists
|
||||||
|
optional: true
|
||||||
|
default: value
|
||||||
|
|
@ -8,5 +8,5 @@ var:
|
||||||
{% for item in trange(0, 10) %}
|
{% for item in trange(0, 10) %}
|
||||||
{{ item }}
|
{{ item }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
return_type: number
|
return_type: integer
|
||||||
description: choice for 0 to 9
|
description: choice for 0 to 9
|
||||||
|
|
|
||||||
12
structures/00_9default_number/rougail/00-base.yml
Normal file
12
structures/00_9default_number/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
version: '1.1'
|
||||||
|
var:
|
||||||
|
description: a variable
|
||||||
|
default: 9
|
||||||
|
choices:
|
||||||
|
jinja: |+
|
||||||
|
{% for item in trange(0, 10) %}
|
||||||
|
{{ item }}
|
||||||
|
{%- endfor %}
|
||||||
|
return_type: number
|
||||||
|
description: choice for 0 to 9
|
||||||
|
|
@ -8,7 +8,7 @@ var2:
|
||||||
- 0
|
- 0
|
||||||
var3:
|
var3:
|
||||||
description: the third variable
|
description: the third variable
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
- 0
|
- 0
|
||||||
var4: # the forth variable
|
var4: # the forth variable
|
||||||
|
|
@ -19,7 +19,7 @@ var5:
|
||||||
- 10
|
- 10
|
||||||
var6:
|
var6:
|
||||||
description: the sixth variable
|
description: the sixth variable
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
- 10
|
- 10
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ var7:
|
||||||
- 0
|
- 0
|
||||||
var8:
|
var8:
|
||||||
description: the eighth variable
|
description: the eighth variable
|
||||||
type: number
|
type: integer
|
||||||
multi: true
|
multi: true
|
||||||
default:
|
default:
|
||||||
- 0
|
- 0
|
||||||
13
structures/01_9choice_variable_optional/rougail/00-base.yml
Normal file
13
structures/01_9choice_variable_optional/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
variable:
|
||||||
|
description: a variable
|
||||||
|
choices:
|
||||||
|
variable: _.unknown_variable
|
||||||
|
optional: true
|
||||||
|
default:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
- c
|
||||||
|
default: c
|
||||||
8
structures/04_0type_param_integer/rougail/00-base.yml
Normal file
8
structures/04_0type_param_integer/rougail/00-base.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
version: '1.1'
|
||||||
|
int:
|
||||||
|
description: A limited integer
|
||||||
|
default: 10
|
||||||
|
params:
|
||||||
|
min_integer: 0
|
||||||
|
max_integer: 100
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
condition: false # a condition
|
||||||
|
|
||||||
|
var1:
|
||||||
|
description: a first variable
|
||||||
|
mandatory: false
|
||||||
|
hidden:
|
||||||
|
variable: _.unknown
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
var2:
|
||||||
|
description: a first variable
|
||||||
|
mandatory: false
|
||||||
|
hidden:
|
||||||
|
variable: _.unknown
|
||||||
|
optional: true
|
||||||
|
default: true
|
||||||
|
|
||||||
|
var3:
|
||||||
|
description: a second variable
|
||||||
|
mandatory: false
|
||||||
|
hidden:
|
||||||
|
variable: _.condition
|
||||||
|
optional: true
|
||||||
|
default: true
|
||||||
|
|
||||||
|
var4:
|
||||||
|
description: a forth variable
|
||||||
|
mandatory: false
|
||||||
|
hidden:
|
||||||
|
variable: _.condition
|
||||||
|
optional: true
|
||||||
|
default: false
|
||||||
|
...
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
version: '1.1'
|
version: '1.1'
|
||||||
int:
|
int:
|
||||||
description: A number
|
description: An integer
|
||||||
type: number
|
type: integer
|
||||||
validators:
|
validators:
|
||||||
- jinja: |
|
- jinja: |
|
||||||
{% if _.int > 100 %}
|
{% if _.int > 100 %}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
version: '1.1'
|
version: '1.1'
|
||||||
general: # a family
|
general: # a family
|
||||||
int:
|
int:
|
||||||
description: a first number
|
description: a first integer
|
||||||
type: number
|
type: integer
|
||||||
test:
|
test:
|
||||||
- 5
|
- 5
|
||||||
validators:
|
validators:
|
||||||
|
|
@ -25,4 +25,4 @@ general: # a family
|
||||||
variable: _.int3
|
variable: _.int3
|
||||||
optional: true
|
optional: true
|
||||||
description: int and int3 must be different
|
description: int and int3 must be different
|
||||||
int2: 1 # a second number
|
int2: 1 # a second integer
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ leader:
|
||||||
- c
|
- c
|
||||||
follower1:
|
follower1:
|
||||||
description: a follower
|
description: a follower
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
type: index
|
type: index
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
version: '1.1'
|
||||||
|
leader:
|
||||||
|
description: a leadership
|
||||||
|
type: leadership
|
||||||
|
leader: # a leader
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
- c
|
||||||
|
follower1:
|
||||||
|
description: a follower
|
||||||
|
default:
|
||||||
|
type: index
|
||||||
|
|
@ -9,7 +9,7 @@ leader:
|
||||||
- c
|
- c
|
||||||
follower1:
|
follower1:
|
||||||
description: a follower
|
description: a follower
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
jinja: '{{ index }}'
|
jinja: '{{ index }}'
|
||||||
params:
|
params:
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@ version: '1.1'
|
||||||
bool: false # a boolean variable
|
bool: false # a boolean variable
|
||||||
int1:
|
int1:
|
||||||
description: first integer variable
|
description: first integer variable
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
jinja: |
|
jinja: |
|
||||||
{% if rougail.bool %}1{% else %}2{% endif %}
|
{% if rougail.bool %}1{% else %}2{% endif %}
|
||||||
description: if bool returns 1 otherwise return 2
|
description: if bool returns 1 otherwise return 2
|
||||||
int2:
|
int2:
|
||||||
description: second integer variable
|
description: second integer variable
|
||||||
type: number
|
type: integer
|
||||||
default:
|
default:
|
||||||
jinja: |
|
jinja: |
|
||||||
{% if not rougail.bool %}3{% else %}4{% endif %}
|
{% if not rougail.bool %}3{% else %}4{% endif %}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
version: '1.1'
|
||||||
|
|
||||||
|
leadership:
|
||||||
|
description: a leadership
|
||||||
|
type: leadership
|
||||||
|
|
||||||
|
leader:
|
||||||
|
description: aleader
|
||||||
|
default:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
|
||||||
|
follower:
|
||||||
|
description: a follower
|
||||||
|
default: value
|
||||||
|
disabled:
|
||||||
|
jinja: |
|
||||||
|
{% if not index %}
|
||||||
|
the first follower
|
||||||
|
{% endif %}
|
||||||
|
params:
|
||||||
|
index:
|
||||||
|
type: index
|
||||||
|
|
@ -4,7 +4,7 @@ var:
|
||||||
description: a suffix variable
|
description: a suffix variable
|
||||||
multi: true
|
multi: true
|
||||||
mandatory: false
|
mandatory: false
|
||||||
type: number
|
type: integer
|
||||||
test:
|
test:
|
||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
"dyn{{ identifier }}":
|
||||||
|
description: a dynamic family
|
||||||
|
dynamic:
|
||||||
|
variable: _.unknown_var
|
||||||
|
optional: true
|
||||||
|
default:
|
||||||
|
- a
|
||||||
|
- b
|
||||||
|
|
||||||
|
var: val # a variable inside dynamic family
|
||||||
|
...
|
||||||
|
|
@ -20,7 +20,9 @@ var:
|
||||||
default:
|
default:
|
||||||
jinja: |
|
jinja: |
|
||||||
{% for val in __.var %}
|
{% for val in __.var %}
|
||||||
|
{% if val is not none %}
|
||||||
t{{ val }}
|
t{{ val }}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
description: add 't' to each var value
|
description: add 't' to each var value
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue