can access to extra variables
This commit is contained in:
parent
3eb208b2c1
commit
509bf21d08
7 changed files with 138 additions and 7 deletions
|
@ -241,6 +241,19 @@ class CreoleLeader:
|
|||
self.slave[name] = values
|
||||
|
||||
|
||||
class CreoleExtra:
|
||||
def __init__(self,
|
||||
suboption: Dict) -> None:
|
||||
self.suboption = suboption
|
||||
|
||||
def __getattr__(self,
|
||||
key: str) -> Any:
|
||||
return self.suboption[key]
|
||||
|
||||
def __repr__(self):
|
||||
return self.suboption.__str__()
|
||||
|
||||
|
||||
class CreoleTemplateEngine:
|
||||
"""Engine to process Creole cheetah template
|
||||
"""
|
||||
|
@ -261,10 +274,21 @@ class CreoleTemplateEngine:
|
|||
eos[func] = getattr(eosfunc, func)
|
||||
self.eosfunc = eos
|
||||
self.creole_variables_dict = {}
|
||||
self.load_eole_variables(self.config, self.config.option('creole'))
|
||||
for option in self.config.option.list(type='all'):
|
||||
namespace = option.option.name()
|
||||
if namespace == 'containers':
|
||||
continue
|
||||
elif namespace == 'creole':
|
||||
self.load_eole_variables_creole(self.config,
|
||||
option)
|
||||
else:
|
||||
self.load_eole_variables(self.config,
|
||||
namespace,
|
||||
option)
|
||||
|
||||
def load_eole_variables(self, config, optiondescription):
|
||||
# remplacement des variables EOLE
|
||||
def load_eole_variables_creole(self,
|
||||
config,
|
||||
optiondescription):
|
||||
for option in optiondescription.list('all'):
|
||||
if option.option.isoptiondescription():
|
||||
if option.option.isleadership():
|
||||
|
@ -277,10 +301,34 @@ class CreoleTemplateEngine:
|
|||
suboption.option.name(),
|
||||
suboption.option.path())
|
||||
else:
|
||||
self.load_eole_variables(config, option)
|
||||
self.load_eole_variables_creole(config,
|
||||
option)
|
||||
else:
|
||||
self.creole_variables_dict[option.option.name()] = option.value.get()
|
||||
|
||||
def load_eole_variables(self,
|
||||
config,
|
||||
namespace,
|
||||
optiondescription):
|
||||
families = {}
|
||||
for family in optiondescription.list('all'):
|
||||
variables = {}
|
||||
for variable in family.list('all'):
|
||||
if variable.option.isoptiondescription() and variable.option.isleadership():
|
||||
for idx, suboption in enumerate(variable.list('all')):
|
||||
if idx == 0:
|
||||
leader = CreoleLeader(suboption.value.get())
|
||||
leader_name = suboption.value.name()
|
||||
else:
|
||||
leader.add_slave(config,
|
||||
suboption.option.name(),
|
||||
suboption.option.path())
|
||||
variables[leader_name] = leader
|
||||
else:
|
||||
variables[variable.option.name()] = variable.value.get()
|
||||
families[family.option.name()] = CreoleExtra(variables)
|
||||
self.creole_variables_dict[namespace] = CreoleExtra(families)
|
||||
|
||||
def patch_template(self,
|
||||
filename: str):
|
||||
"""Apply patch to a template
|
||||
|
|
84
tests/templates/60extra/00-base.xml
Normal file
84
tests/templates/60extra/00-base.xml
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="général" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>force_default_on_freeze</property>
|
||||
<property>frozen</property>
|
||||
<property>hidden</property>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<variable doc="No change" multi="False" name="activer_ejabberd" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>force_default_on_freeze</property>
|
||||
<property>frozen</property>
|
||||
<property>hidden</property>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
<family doc="" name="extra">
|
||||
<family doc="ejabberd" name="ejabberd">
|
||||
<property>normal</property>
|
||||
<variable doc="description" multi="False" name="description" type="string">
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value>Exportation de la base de ejabberd</value>
|
||||
</variable>
|
||||
<variable doc="day" multi="False" name="day" type="choice">
|
||||
<choice type="string">none</choice>
|
||||
<choice type="string">daily</choice>
|
||||
<choice type="string">weekly</choice>
|
||||
<choice type="string">monthly</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value name="calc_multi_condition" type="calculation">
|
||||
<param transitive="False" type="string">non</param>
|
||||
<param name="condition_1" type="variable">creole.general.activer_ejabberd</param>
|
||||
<param name="match" transitive="False" type="string">none</param>
|
||||
<param name="mismatch" transitive="False" type="string">daily</param>
|
||||
</value>
|
||||
</variable>
|
||||
<variable doc="mode" multi="False" name="mode" type="choice">
|
||||
<choice type="string">pre</choice>
|
||||
<choice type="string">post</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">pre</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
</creole>
|
1
tests/templates/60extra/result/test/etc/mailname
Normal file
1
tests/templates/60extra/result/test/etc/mailname
Normal file
|
@ -0,0 +1 @@
|
|||
Exportation de la base de ejabberd
|
1
tests/templates/60extra/tmpl/mailname
Normal file
1
tests/templates/60extra/tmpl/mailname
Normal file
|
@ -0,0 +1 @@
|
|||
%%extra.ejabberd.description
|
|
@ -1 +0,0 @@
|
|||
mailname
|
|
@ -1 +0,0 @@
|
|||
mailname2
|
|
@ -1 +0,0 @@
|
|||
%%rougail_variable
|
Loading…
Reference in a new issue