tiramisu is now async

This commit is contained in:
Emmanuel Garette 2020-01-13 19:44:24 +01:00
parent 1c5ab706ed
commit 963e93295a
1 changed files with 53 additions and 57 deletions

View File

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