dynamic option description and filename with calculation
This commit is contained in:
@ -266,8 +266,12 @@ class ContainerAnnotator:
|
||||
disknod.permission = 'allow'
|
||||
|
||||
def _update_file(self, file_, index, container_path):
|
||||
if not hasattr(file_, 'source'):
|
||||
file_.source = basename(file_.name)
|
||||
if file_.name_type == "UnicodeOption":
|
||||
if not hasattr(file_, 'source'):
|
||||
file_.source = basename(file_.name)
|
||||
elif not hasattr(file_, 'source'):
|
||||
raise CreoleDictConsistencyError(_('attribute source mandatory for file with SymLinkOption name '
|
||||
'for {}').format(file_.name))
|
||||
|
||||
def _split_elts(self, name, key, value, elt):
|
||||
"""for example::
|
||||
@ -483,6 +487,7 @@ class SpaceAnnotator(object):
|
||||
self.remove_empty_families()
|
||||
self.change_variable_mode()
|
||||
self.change_family_mode()
|
||||
self.dynamic_families()
|
||||
self.filter_separators()
|
||||
self.absolute_path_for_symlink_in_containers()
|
||||
self.convert_helps()
|
||||
@ -611,6 +616,17 @@ class SpaceAnnotator(object):
|
||||
else:
|
||||
family.mode = mode
|
||||
|
||||
def dynamic_families(self): # pylint: disable=C0111
|
||||
if not hasattr(self.space, 'variables'):
|
||||
return
|
||||
for family in self.space.variables.values():
|
||||
if hasattr(family, 'family'):
|
||||
for family in family.family.values():
|
||||
if 'dynamic' in vars(family):
|
||||
namespace = self.paths.get_variable_namespace(family.dynamic)
|
||||
varpath = self.paths.get_variable_path(family.dynamic, namespace)
|
||||
family.dynamic = varpath
|
||||
|
||||
def _annotate_variable(self, variable, family_mode, path, is_follower=False):
|
||||
if (HIGH_COMPATIBILITY and variable.type == 'choice' and variable.mode != modes_level[-1] and variable.mandatory is True and path in self.default_has_no_value):
|
||||
variable.mode = modes_level[0]
|
||||
|
@ -6,7 +6,7 @@ from os import listdir
|
||||
#from ast import literal_eval
|
||||
from lxml.etree import parse, DTD
|
||||
|
||||
from tiramisu.option import (StrOption, OptionDescription, PortOption,
|
||||
from tiramisu.option import (StrOption, OptionDescription, DynOptionDescription, PortOption,
|
||||
IntOption, ChoiceOption, BoolOption, SymLinkOption, IPOption,
|
||||
NetworkOption, NetmaskOption, DomainnameOption, BroadcastOption,
|
||||
URLOption, EmailOption, FilenameOption, UsernameOption, DateOption,
|
||||
@ -117,9 +117,9 @@ class PopulateTiramisuObjects(object):
|
||||
|
||||
def make_tiramisu_objects(self, xmlroot, creolefunc_file):
|
||||
elt = Elt({'name': 'baseoption'})
|
||||
family = Family(elt, self.booleans, self.storage)
|
||||
self.storage.add('.', family)
|
||||
self.eosfunc = imp.load_source('eosfunc', creolefunc_file)
|
||||
family = Family(elt, self.booleans, self.storage, self.eosfunc)
|
||||
self.storage.add('.', family)
|
||||
|
||||
elts = {}
|
||||
for elt in xmlroot:
|
||||
@ -167,7 +167,7 @@ class PopulateTiramisuObjects(object):
|
||||
force_icon = False
|
||||
else:
|
||||
force_icon = not subpath.startswith('containers') and not subpath.startswith('actions')
|
||||
family = Family(elt, self.booleans, self.storage, force_icon)
|
||||
family = Family(elt, self.booleans, self.storage, self.eosfunc, force_icon)
|
||||
path = self._build_path(subpath, elt)
|
||||
self.storage.add(path, family)
|
||||
return family
|
||||
@ -181,7 +181,7 @@ class PopulateTiramisuObjects(object):
|
||||
|
||||
def _iter_leader(self, leader, subpath):
|
||||
subpath = self._build_path(subpath, leader)
|
||||
family = Family(leader, self.booleans, self.storage)
|
||||
family = Family(leader, self.booleans, self.storage, self.eosfunc)
|
||||
family.set_leader()
|
||||
self.storage.add(subpath, family)
|
||||
leader_name = None
|
||||
@ -474,7 +474,7 @@ class Variable(Common):
|
||||
|
||||
|
||||
class Family(Common):
|
||||
def __init__(self, elt, booleans, storage, force_icon=False):
|
||||
def __init__(self, elt, booleans, storage, eosfunc, force_icon=False):
|
||||
self.option = None
|
||||
self.attrib = {}
|
||||
self.is_leader = False
|
||||
@ -484,6 +484,7 @@ class Family(Common):
|
||||
self.informations = {}
|
||||
self.children = []
|
||||
self.storage = storage
|
||||
self.eosfunc = eosfunc
|
||||
self.attrib['properties'] = []
|
||||
for key, value in elt.attrib.items():
|
||||
if key in booleans:
|
||||
@ -528,11 +529,16 @@ class Family(Common):
|
||||
self.attrib['children'].append(child.get())
|
||||
self.build_properties()
|
||||
try:
|
||||
if not self.is_leader:
|
||||
if 'dynamic' in self.attrib:
|
||||
dynamic = self.storage.get(self.attrib['dynamic']).get()
|
||||
del self.attrib['dynamic']
|
||||
self.attrib['suffixes'] = Calculation(self.eosfunc.calc_value,
|
||||
Params((ParamOption(dynamic),)))
|
||||
option = DynOptionDescription(**self.attrib)
|
||||
elif not self.is_leader:
|
||||
option = OptionDescription(**self.attrib)
|
||||
else:
|
||||
option = Leadership(**self.attrib)
|
||||
#option = OptionDescription(**self.attrib)
|
||||
except Exception as err:
|
||||
raise CreoleLoaderError(_('cannot create optiondescription {}: {}').format(self.attrib['name'], err))
|
||||
for key, value in self.informations.items():
|
||||
|
Reference in New Issue
Block a user