tiramisu is now async

This commit is contained in:
Emmanuel Garette 2020-01-13 19:44:24 +01:00
parent 1c5ab706ed
commit 963e93295a

View file

@ -114,8 +114,6 @@ class CheetahTemplate(ChtTemplate):
filename: str, filename: str,
context, context,
eosfunc: Dict, eosfunc: Dict,
config: Config,
current_container: str,
destfilename, destfilename,
variable): variable):
"""Initialize Creole CheetahTemplate """Initialize Creole CheetahTemplate
@ -228,12 +226,12 @@ class CreoleLeader:
def __contains__(self, item): def __contains__(self, item):
return item in self._value return item in self._value
def add_slave(self, config, name, path): async def add_slave(self, config, name, path):
if isinstance(self._value, list): if isinstance(self._value, list):
values = [] values = []
for idx in range(len(self._value)): for idx in range(len(self._value)):
try: try:
values.append(config.option(path, idx).value.get()) values.append(await config.option(path, idx).value.get())
except PropertiesOptionError as err: except PropertiesOptionError as err:
values.append(err) values.append(err)
else: else:
@ -274,59 +272,48 @@ class CreoleTemplateEngine:
eos[func] = getattr(eosfunc, func) eos[func] = getattr(eosfunc, func)
self.eosfunc = eos self.eosfunc = eos
self.creole_variables_dict = {} self.creole_variables_dict = {}
for option in self.config.option.list(type='all'):
namespace = option.option.name()
if namespace in ['containers', 'actions']:
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_creole(self, async def load_eole_variables_creole(self,
config, config,
optiondescription): optiondescription):
for option in optiondescription.list('all'): for option in await optiondescription.list('all'):
if option.option.isoptiondescription(): if await option.option.isoptiondescription():
if option.option.isleadership(): if await option.option.isleadership():
for idx, suboption in enumerate(option.list('all')): for idx, suboption in enumerate(await option.list('all')):
if idx == 0: if idx == 0:
leader = CreoleLeader(suboption.value.get()) leader = CreoleLeader(await suboption.value.get())
self.creole_variables_dict[suboption.option.name()] = leader self.creole_variables_dict[await suboption.option.name()] = leader
else: else:
leader.add_slave(config, await leader.add_slave(config,
suboption.option.name(), await suboption.option.name(),
suboption.option.path()) await suboption.option.path())
else: else:
self.load_eole_variables_creole(config, await self.load_eole_variables_creole(config,
option) option)
else: else:
self.creole_variables_dict[option.option.name()] = option.value.get() self.creole_variables_dict[await option.option.name()] = await option.value.get()
def load_eole_variables(self, async def load_eole_variables(self,
config, config,
namespace, namespace,
optiondescription): optiondescription):
families = {} families = {}
for family in optiondescription.list('all'): for family in await optiondescription.list('all'):
variables = {} variables = {}
for variable in family.list('all'): for variable in await family.list('all'):
if variable.option.isoptiondescription() and variable.option.isleadership(): if await variable.option.isoptiondescription() and await variable.option.isleadership():
for idx, suboption in enumerate(variable.list('all')): for idx, suboption in enumerate(await variable.list('all')):
if idx == 0: if idx == 0:
leader = CreoleLeader(suboption.value.get()) leader = CreoleLeader(await suboption.value.get())
leader_name = suboption.option.name() leader_name = await suboption.option.name()
else: else:
leader.add_slave(config, await leader.add_slave(config,
suboption.option.name(), await suboption.option.name(),
suboption.option.path()) await suboption.option.path())
variables[leader_name] = leader variables[leader_name] = leader
else: else:
variables[variable.option.name()] = variable.value.get() variables[await variable.option.name()] = await variable.value.get()
families[family.option.name()] = CreoleExtra(variables) families[await family.option.name()] = CreoleExtra(variables)
self.creole_variables_dict[namespace] = CreoleExtra(families) self.creole_variables_dict[namespace] = CreoleExtra(families)
def patch_template(self, def patch_template(self,
@ -388,8 +375,6 @@ class CreoleTemplateEngine:
filevar['source']), filevar['source']),
self.creole_variables_dict, self.creole_variables_dict,
self.eosfunc, self.eosfunc,
self.config.config.copy(),
container,
destfilename, destfilename,
variable) variable)
data = str(cheetah_template) data = str(cheetah_template)
@ -471,23 +456,34 @@ class CreoleTemplateEngine:
self.change_properties(destfilename, self.change_properties(destfilename,
filevar) filevar)
def instance_files(self, async def instance_files(self,
container=None): container=None):
"""Run templatisation on all files of all containers """Run templatisation on all files of all containers
@param container: name of a container @param container: name of a container
@type container: C{str} @type container: C{str}
""" """
for option in await self.config.option.list(type='all'):
namespace = await option.option.name()
if namespace in ['containers', 'actions']:
continue
elif namespace == 'creole':
await self.load_eole_variables_creole(self.config,
option)
else:
await self.load_eole_variables(self.config,
namespace,
option)
for template in listdir(self.distrib_dir): for template in listdir(self.distrib_dir):
self.prepare_template(join(self.distrib_dir, template)) self.prepare_template(join(self.distrib_dir, template))
for container_obj in self.config.option('containers').list('all'): for container_obj in await self.config.option('containers').list('all'):
current_container = container_obj.option.doc() current_container = await container_obj.option.doc()
if container is not None and container != current_container: if container is not None and container != current_container:
continue continue
for fills in container_obj.list('all'): for fills in await container_obj.list('all'):
if fills.option.name() == 'files': if await fills.option.name() == 'files':
for fill_obj in fills.list('all'): for fill_obj in await fills.list('all'):
fill = fill_obj.value.dict() fill = await fill_obj.value.dict()
filename = fill['source'] filename = fill['source']
distib_file = join(self.distrib_dir, filename) distib_file = join(self.distrib_dir, filename)
if not isfile(distib_file): if not isfile(distib_file):
@ -499,7 +495,7 @@ class CreoleTemplateEngine:
log.debug(_("Instantiation of file '{filename}' disabled")) log.debug(_("Instantiation of file '{filename}' disabled"))
def generate(config: Config, async def generate(config: Config,
eosfunc_file: str, eosfunc_file: str,
distrib_dir: str, distrib_dir: str,
tmp_dir: str, tmp_dir: str,
@ -510,4 +506,4 @@ def generate(config: Config,
distrib_dir, distrib_dir,
tmp_dir, tmp_dir,
dest_dir) dest_dir)
engine.instance_files(container=container) await engine.instance_files(container=container)