add remove fill without fill test + patches_dir is multi
This commit is contained in:
parent
3c5d4a4fa6
commit
f91132fc61
7 changed files with 148 additions and 87 deletions
|
@ -62,7 +62,7 @@ log.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
INFORMATIONS = {'files': ['source', 'mode', 'engine', 'included'],
|
INFORMATIONS = {'files': ['source', 'mode', 'engine', 'included'],
|
||||||
'overrides': ['name', 'source', 'engine'],
|
'overrides': ['name', 'source', 'engine'],
|
||||||
'service_names': ['doc', 'engine', 'type'],
|
'service_names': ['doc', 'engine', 'type', 'target', 'undisable'],
|
||||||
}
|
}
|
||||||
DEFAULT = {'files': ['owner', 'group'],
|
DEFAULT = {'files': ['owner', 'group'],
|
||||||
'overrides': [],
|
'overrides': [],
|
||||||
|
@ -178,6 +178,10 @@ class RougailLeader:
|
||||||
def index(self, value):
|
def index(self, value):
|
||||||
return self._value.index(value)
|
return self._value.index(value)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
followers_name = list(self._follower)
|
||||||
|
return f'RougailLeader({followers_name[0]}) => {followers_name[1:]}'
|
||||||
|
|
||||||
|
|
||||||
class RougailExtra:
|
class RougailExtra:
|
||||||
"""Object that implement access to extra variable
|
"""Object that implement access to extra variable
|
||||||
|
@ -212,7 +216,7 @@ class RougailExtra:
|
||||||
return self._suboption.items()
|
return self._suboption.items()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self._name
|
return f'RougailExtra("{self._name}") => {self._suboption}'
|
||||||
|
|
||||||
|
|
||||||
class RougailBaseTemplate:
|
class RougailBaseTemplate:
|
||||||
|
@ -233,7 +237,12 @@ class RougailBaseTemplate:
|
||||||
templates_dir = [templates_dir]
|
templates_dir = [templates_dir]
|
||||||
for templ_dir in templates_dir:
|
for templ_dir in templates_dir:
|
||||||
self.templates_dir.append(abspath(templ_dir))
|
self.templates_dir.append(abspath(templ_dir))
|
||||||
self.patches_dir = abspath(rougailconfig['patches_dir'])
|
patches_dir = rougailconfig['patches_dir']
|
||||||
|
if not isinstance(patches_dir, list):
|
||||||
|
patches_dir = [patches_dir]
|
||||||
|
self.patches_dir = []
|
||||||
|
for p_dir in patches_dir:
|
||||||
|
self.patches_dir.append(abspath(p_dir))
|
||||||
eos = {}
|
eos = {}
|
||||||
functions_file = rougailconfig['functions_file']
|
functions_file = rougailconfig['functions_file']
|
||||||
if not isinstance(functions_file, list):
|
if not isinstance(functions_file, list):
|
||||||
|
@ -259,16 +268,17 @@ class RougailBaseTemplate:
|
||||||
patch_cmd = ['patch', '-d', self.tmp_dir, '-N', '-p1', '-f']
|
patch_cmd = ['patch', '-d', self.tmp_dir, '-N', '-p1', '-f']
|
||||||
patch_no_debug = ['-s', '-r', '-', '--backup-if-mismatch']
|
patch_no_debug = ['-s', '-r', '-', '--backup-if-mismatch']
|
||||||
|
|
||||||
patch_file = join(self.patches_dir, f'{filename}.patch')
|
for patches_dir in self.patches_dir:
|
||||||
if isfile(patch_file):
|
patch_file = join(patches_dir, f'{filename}.patch')
|
||||||
self.log.info(_("Patching template '{filename}' with '{patch_file}'"))
|
if isfile(patch_file):
|
||||||
ret = call(patch_cmd + patch_no_debug + ['-i', patch_file])
|
self.log.info(_("Patching template '{filename}' with '{patch_file}'"))
|
||||||
if ret: # pragma: no cover
|
ret = call(patch_cmd + patch_no_debug + ['-i', patch_file])
|
||||||
patch_cmd_err = ' '.join(patch_cmd + ['-i', patch_file])
|
if ret: # pragma: no cover
|
||||||
msg = _(f"Error applying patch: '{patch_file}'\n"
|
patch_cmd_err = ' '.join(patch_cmd + ['-i', patch_file])
|
||||||
f"To reproduce and fix this error {patch_cmd_err}")
|
msg = _(f"Error applying patch: '{patch_file}'\n"
|
||||||
self.log.error(_(msg))
|
f"To reproduce and fix this error {patch_cmd_err}")
|
||||||
copy(join(templates_dir, filename), self.tmp_dir)
|
self.log.error(_(msg))
|
||||||
|
copy(join(templates_dir, filename), self.tmp_dir)
|
||||||
|
|
||||||
def prepare_template(self,
|
def prepare_template(self,
|
||||||
filename: str,
|
filename: str,
|
||||||
|
@ -362,65 +372,70 @@ class RougailBaseTemplate:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
ori_dir = None
|
ori_dir = None
|
||||||
chdir(self.tmp_dir)
|
chdir(self.tmp_dir)
|
||||||
if not self.rougail_variables_dict:
|
try:
|
||||||
await self.load_variables()
|
if not self.rougail_variables_dict:
|
||||||
for templates_dir in self.templates_dir:
|
await self.load_variables()
|
||||||
for template in listdir(templates_dir):
|
for templates_dir in self.templates_dir:
|
||||||
self.prepare_template(template,
|
for template in listdir(templates_dir):
|
||||||
templates_dir,
|
self.prepare_template(template,
|
||||||
)
|
templates_dir,
|
||||||
files_to_delete = []
|
)
|
||||||
for included in (True, False):
|
files_to_delete = []
|
||||||
for service_obj in await self.config.option('services').list('all'):
|
for included in (True, False):
|
||||||
service_name = await service_obj.option.description()
|
for service_obj in await self.config.option('services').list('all'):
|
||||||
if await service_obj.option('activate').value.get() is False:
|
service_name = await service_obj.option.description()
|
||||||
if included is False and not await service_obj.information.get('undisable', False):
|
if await service_obj.option('activate').value.get() is False:
|
||||||
self.desactive_service(service_name)
|
if included is False and not await service_obj.information.get('undisable', False):
|
||||||
continue
|
self.desactive_service(service_name)
|
||||||
if not included:
|
continue
|
||||||
engine = await service_obj.information.get('engine', None)
|
if not included:
|
||||||
if engine:
|
engine = await service_obj.information.get('engine', None)
|
||||||
self.instance_file({'engine': engine},
|
if engine:
|
||||||
'service',
|
self.instance_file({'engine': engine},
|
||||||
service_name,
|
'service',
|
||||||
)
|
service_name,
|
||||||
target_name = await service_obj.information.get('target', None)
|
)
|
||||||
if target_name:
|
target_name = await service_obj.information.get('target', None)
|
||||||
self.target_service(service_name,
|
if target_name:
|
||||||
target_name,
|
self.target_service(service_name,
|
||||||
engine is None,
|
target_name,
|
||||||
)
|
engine is None,
|
||||||
for fills in await service_obj.list('optiondescription'):
|
)
|
||||||
type_ = await fills.option.name()
|
for fills in await service_obj.list('optiondescription'):
|
||||||
for fill_obj in await fills.list('all'):
|
type_ = await fills.option.name()
|
||||||
fill = await fill_obj.value.dict()
|
for fill_obj in await fills.list('all'):
|
||||||
self.get_default(type_, fill, fill_obj)
|
fill = await fill_obj.value.dict()
|
||||||
await self.get_informations(type_, fill, fill_obj)
|
self.get_default(type_, fill, fill_obj)
|
||||||
if 'included' in fill:
|
await self.get_informations(type_, fill, fill_obj)
|
||||||
if (fill['included'] == 'no' and included is True) or \
|
if 'included' in fill:
|
||||||
(fill['included'] != 'no' and included is False):
|
if (fill['included'] == 'no' and included is True) or \
|
||||||
|
(fill['included'] != 'no' and included is False):
|
||||||
|
continue
|
||||||
|
elif included is True:
|
||||||
continue
|
continue
|
||||||
elif included is True:
|
if fill['activate']:
|
||||||
continue
|
destfilenames = self.instance_file(fill,
|
||||||
if fill['activate']:
|
type_,
|
||||||
destfilenames = self.instance_file(fill,
|
service_name,
|
||||||
type_,
|
)
|
||||||
service_name,
|
if included and fill.get('included', 'no') == 'content':
|
||||||
)
|
files_to_delete.extend(destfilenames)
|
||||||
if included and fill.get('included', 'no') == 'content':
|
elif 'name' in fill:
|
||||||
files_to_delete.extend(destfilenames)
|
self.log.debug(_(f"Instantiation of file '{fill['name']}' disabled"))
|
||||||
elif 'name' in fill:
|
self.post_instance_service(service_name)
|
||||||
self.log.debug(_(f"Instantiation of file '{fill['name']}' disabled"))
|
for filename in files_to_delete:
|
||||||
self.post_instance_service(service_name)
|
unlink(filename)
|
||||||
for filename in files_to_delete:
|
parent = filename
|
||||||
unlink(filename)
|
while True:
|
||||||
parent = filename
|
parent = dirname(parent)
|
||||||
while True:
|
if listdir(parent):
|
||||||
parent = dirname(parent)
|
break
|
||||||
if listdir(parent):
|
rmdir(parent)
|
||||||
break
|
self.post_instance()
|
||||||
rmdir(parent)
|
except Exception as err:
|
||||||
self.post_instance()
|
if ori_dir is not None:
|
||||||
|
chdir(ori_dir)
|
||||||
|
raise err
|
||||||
if ori_dir is not None:
|
if ori_dir is not None:
|
||||||
chdir(ori_dir)
|
chdir(ori_dir)
|
||||||
|
|
||||||
|
@ -443,12 +458,21 @@ class RougailBaseTemplate:
|
||||||
obj: 'Option',
|
obj: 'Option',
|
||||||
) -> None:
|
) -> None:
|
||||||
for key in INFORMATIONS.get(type_, []):
|
for key in INFORMATIONS.get(type_, []):
|
||||||
default_key = f'default_{type_}_{key}'
|
if key == 'target':
|
||||||
if default_key in RougailConfig:
|
default_value = None
|
||||||
default_value = RougailConfig[default_key]
|
elif key == 'undisable':
|
||||||
|
default_value = False
|
||||||
|
elif key == 'engine' and type_ == 'service_names':
|
||||||
|
default_value = None
|
||||||
else:
|
else:
|
||||||
default_value = undefined
|
default_key = f'default_{type_}_{key}'
|
||||||
dico[key] = await obj.information.get(key, default_value)
|
if default_key in RougailConfig:
|
||||||
|
default_value = RougailConfig[default_key]
|
||||||
|
else:
|
||||||
|
default_value = undefined
|
||||||
|
value = await obj.information.get(key, default_value)
|
||||||
|
if key not in ['target', 'undisable'] or value != default_value:
|
||||||
|
dico[key] = await obj.information.get(key, default_value)
|
||||||
|
|
||||||
def desactive_service(self,
|
def desactive_service(self,
|
||||||
*args,
|
*args,
|
||||||
|
@ -547,7 +571,7 @@ class RougailBaseTemplate:
|
||||||
await suboption.option.name(),
|
await suboption.option.name(),
|
||||||
path,
|
path,
|
||||||
)
|
)
|
||||||
variables[leadership_name] = RougailExtra(await optiondescription.option.name(), {leader_name: leader}, await optiondescription.option.path())
|
variables[leadership_name] = RougailExtra(await option.option.name(), {leader_name: leader}, await option.option.path())
|
||||||
else:
|
else:
|
||||||
if is_service_namespace == 'root':
|
if is_service_namespace == 'root':
|
||||||
new_is_service_namespace = 'service_name'
|
new_is_service_namespace = 'service_name'
|
||||||
|
@ -567,16 +591,7 @@ class RougailBaseTemplate:
|
||||||
if is_variable_namespace:
|
if is_variable_namespace:
|
||||||
value = await option.value.get()
|
value = await option.value.get()
|
||||||
self.rougail_variables_dict[await option.option.name()] = value
|
self.rougail_variables_dict[await option.option.name()] = value
|
||||||
if await option.option.issymlinkoption() and await option.option.isfollower():
|
value = await option.value.get()
|
||||||
value = []
|
|
||||||
if isinstance(self.config, TiramisuOption):
|
|
||||||
path = (await option.option.path())[len_root_path:]
|
|
||||||
else:
|
|
||||||
path = await option.option.path()
|
|
||||||
for index in range(await option.value.len()):
|
|
||||||
value.append(await self.config.option(path, index).value.get())
|
|
||||||
else:
|
|
||||||
value = await option.value.get()
|
|
||||||
variables[await option.option.name()] = value
|
variables[await option.option.name()] = value
|
||||||
if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS:
|
if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS:
|
||||||
self.get_default(is_service_namespace + 's',
|
self.get_default(is_service_namespace + 's',
|
||||||
|
|
0
tests/dictionaries/80remove_fill_no_fill/__init__.py
Normal file
0
tests/dictionaries/80remove_fill_no_fill/__init__.py
Normal file
0
tests/dictionaries/80remove_fill_no_fill/errno_89
Normal file
0
tests/dictionaries/80remove_fill_no_fill/errno_89
Normal file
13
tests/dictionaries/80remove_fill_no_fill/xml/00-base.xml
Normal file
13
tests/dictionaries/80remove_fill_no_fill/xml/00-base.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail version="0.10">
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="mode_conteneur_actif" type="string" description="No change">
|
||||||
|
<value>oui</value>
|
||||||
|
</variable>
|
||||||
|
<variable name="mode_conteneur_actif1" type="string" description="No change">
|
||||||
|
<value>non</value>
|
||||||
|
</variable>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
8
tests/dictionaries/80remove_fill_no_fill/xml/01-base.xml
Normal file
8
tests/dictionaries/80remove_fill_no_fill/xml/01-base.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail version="0.10">
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="mode_conteneur_actif" redefine="True" remove_fill="True"/>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
</rougail>
|
16
tests/dictionaries/80remove_fill_no_fill/yml/00-base.yml
Normal file
16
tests/dictionaries/80remove_fill_no_fill/yml/00-base.yml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
version: '0.10'
|
||||||
|
variables:
|
||||||
|
- family:
|
||||||
|
- name: general
|
||||||
|
variables:
|
||||||
|
- variable:
|
||||||
|
- name: mode_conteneur_actif
|
||||||
|
type: string
|
||||||
|
description: No change
|
||||||
|
value:
|
||||||
|
- text: oui
|
||||||
|
- name: mode_conteneur_actif1
|
||||||
|
type: string
|
||||||
|
description: No change
|
||||||
|
value:
|
||||||
|
- text: non
|
9
tests/dictionaries/80remove_fill_no_fill/yml/01-base.yml
Normal file
9
tests/dictionaries/80remove_fill_no_fill/yml/01-base.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
version: '0.10'
|
||||||
|
variables:
|
||||||
|
- family:
|
||||||
|
- name: general
|
||||||
|
variables:
|
||||||
|
- variable:
|
||||||
|
- name: mode_conteneur_actif
|
||||||
|
redefine: true
|
||||||
|
remove_fill: true
|
Loading…
Reference in a new issue