support of variables's file_name
This commit is contained in:
parent
3881cb7e98
commit
1ce16ad05d
10 changed files with 44 additions and 27 deletions
|
@ -11,8 +11,8 @@ import logging
|
|||
from typing import Dict
|
||||
|
||||
from subprocess import call
|
||||
from os import listdir, unlink, mkdir
|
||||
from os.path import basename, join, split, isfile, isdir
|
||||
from os import listdir, unlink, makedirs
|
||||
from os.path import dirname, basename, join, split, isfile, isdir
|
||||
|
||||
from tempfile import mktemp
|
||||
|
||||
|
@ -114,14 +114,16 @@ class CheetahTemplate(ChtTemplate):
|
|||
context,
|
||||
eosfunc: Dict,
|
||||
config: Config,
|
||||
current_container: str):
|
||||
current_container: str,
|
||||
destfilename):
|
||||
"""Initialize Creole CheetahTemplate
|
||||
"""
|
||||
ChtTemplate.__init__(self, file=filename,
|
||||
searchList=[context, eosfunc, {'is_defined' : IsDefined(context),
|
||||
'creole_client' : CreoleClient(config),
|
||||
'current_container':CreoleGet(current_container),
|
||||
}])
|
||||
'rougail_filename': destfilename
|
||||
}])
|
||||
|
||||
|
||||
class CreoleLeader:
|
||||
|
@ -326,11 +328,13 @@ class CreoleTemplateEngine:
|
|||
# full path of the destination file
|
||||
log.info(_(f"Cheetah processing: '{destfilename}'"))
|
||||
try:
|
||||
cheetah_template = CheetahTemplate(join(self.tmp_dir, filevar['source']),
|
||||
cheetah_template = CheetahTemplate(join(self.tmp_dir,
|
||||
filevar['source']),
|
||||
self.creole_variables_dict,
|
||||
self.eosfunc,
|
||||
self.config.config.copy(),
|
||||
container)
|
||||
container,
|
||||
destfilename)
|
||||
data = str(cheetah_template)
|
||||
except CheetahNotFound as err:
|
||||
varname = err.args[0][13:-1]
|
||||
|
@ -386,15 +390,18 @@ class CreoleTemplateEngine:
|
|||
log.info(_("Instantiating file '{filename}'"))
|
||||
container_dir = join(self.dest_dir,
|
||||
container)
|
||||
if not isdir(container_dir):
|
||||
mkdir(container_dir)
|
||||
destfilename = join(container_dir,
|
||||
filevar['source'])
|
||||
self.process(destfilename,
|
||||
filevar,
|
||||
container)
|
||||
self.change_properties(destfilename,
|
||||
filevar)
|
||||
filenames = filevar['name']
|
||||
if not isinstance(filenames, list):
|
||||
filenames = [filenames]
|
||||
for filename in filenames:
|
||||
destfilename = join(container_dir,
|
||||
filename[1:])
|
||||
makedirs(dirname(destfilename), exist_ok=True)
|
||||
self.process(destfilename,
|
||||
filevar,
|
||||
container)
|
||||
self.change_properties(destfilename,
|
||||
filevar)
|
||||
|
||||
def instance_files(self,
|
||||
container=None):
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
description="Reconfigurer le serveur"
|
||||
image="backup.svg"
|
||||
url="extra.test.calc_url"
|
||||
url_type="SymLinkOption">
|
||||
url_type="variable">
|
||||
<input>Reconfigurer</input>
|
||||
<profile>ead_admin</profile>
|
||||
<ewtapp>ead</ewtapp>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<creole>
|
||||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<file name='file_name' name_type="SymLinkOption" source="mailname"/>
|
||||
<file name='file_name' name_type="variable" source="mailname"/>
|
||||
</container>
|
||||
</containers>
|
||||
<variables>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<fstab name='path_fstab' name_type="SymLinkOption"/>
|
||||
<fstab name='path_fstab' name_type="variable"/>
|
||||
</container>
|
||||
</containers>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<service_restriction service='nut'>
|
||||
<ip interface='auto' netmask='nut_monitor_netmask' netmask_type='SymLinkOption' ip_type='SymLinkOption'>nut_monitor_host</ip>
|
||||
<ip interface='auto' netmask='nut_monitor_netmask' netmask_type='variable' ip_type='variable'>nut_monitor_host</ip>
|
||||
</service_restriction>
|
||||
|
||||
</container>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<service_restriction service='nut'>
|
||||
<ip interface='auto' netmask='nut_monitor_netmask' netmask_type='SymLinkOption' ip_type='SymLinkOption'>nut_monitor_host</ip>
|
||||
<ip interface='auto' netmask='nut_monitor_netmask' netmask_type='variable' ip_type='variable'>nut_monitor_host</ip>
|
||||
</service_restriction>
|
||||
|
||||
</container>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<creole>
|
||||
<containers>
|
||||
<container name='test' id='23'>
|
||||
<file name='file_name' name_type="SymLinkOption"/>
|
||||
<file name='file_name' name_type="variable"/>
|
||||
</container>
|
||||
</containers>
|
||||
<variables>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
oui
|
|
@ -1 +0,0 @@
|
|||
non
|
|
@ -18,6 +18,16 @@ def test_dir(request):
|
|||
return request.param
|
||||
|
||||
|
||||
def find_files(dirname, root, files):
|
||||
for filename in listdir(dirname):
|
||||
abs_dirname = join(dirname, filename)
|
||||
root_file = root + [filename]
|
||||
if isdir(join(dirname, filename)):
|
||||
find_files(abs_dirname, root_file, files)
|
||||
else:
|
||||
files.add(join(*root_file))
|
||||
|
||||
|
||||
def test_dictionary(test_dir):
|
||||
test_dir = join(template_dirs, test_dir)
|
||||
tmp_dir = join(test_dir, 'tmp')
|
||||
|
@ -45,13 +55,15 @@ def test_dictionary(test_dir):
|
|||
dest_dir)
|
||||
|
||||
if isdir(join(dest_dir, 'test')):
|
||||
list_templates = set(listdir(join(dest_dir, 'test')))
|
||||
list_templates = set()
|
||||
find_files(join(dest_dir), [], list_templates)
|
||||
else:
|
||||
list_templates = set()
|
||||
list_results = set(listdir(join(test_dir, 'result')))
|
||||
list_results = set()
|
||||
find_files(join(test_dir, 'result'), [], list_results)
|
||||
assert list_templates == list_results
|
||||
for result in listdir(join(test_dir, 'result')):
|
||||
template_file = join(dest_dir, 'test', result)
|
||||
for result in list_results:
|
||||
template_file = join(dest_dir, result)
|
||||
if not isfile(template_file):
|
||||
raise Exception(f'{template_file} is not generated')
|
||||
with open(join(test_dir, 'result', result), 'r') as fh:
|
||||
|
|
Loading…
Reference in a new issue