Commit 80988717 authored by eric pellegrini's avatar eric pellegrini

bug fixed when running packme without templates selection

parent a26b10ec
......@@ -45,8 +45,8 @@ class Packman:
self._templates = data["templates"]
def get_template(self, template_name):
"""Return the YAML contents of a given template.
def get_templates_selection(self, selected_templates = None):
"""Filter out a template selection from those which are not actual ones.
Parameters
----------
......@@ -55,9 +55,34 @@ class Packman:
Returns
-------
:obj: `PackerTemplate`
list
The filtered templates list.
"""
if selected_templates is None:
selected_templates = ["*"]
# If '*' is in the list of the selected templates, pick all the templates found in the templates base directory
if "*" in selected_templates:
templates = self._templates.keys()
else:
# Filter out the image names not present in the yaml file
templates = [template for template in selected_templates if template in self._templates]
return templates
def get_template(self, template_name):
"""Return the YAML contents of a given template.
The YAML contents of the template to be fetched.
Parameters
----------
selected_templates: list, optional
List of strings corresponding to the packer templates from which the hierarchy should be built.
Returns
-------
list
Returns the hierarchy of templates from the one with no parent to the ones with parents.
"""
return self._templates[template_name] if isinstance(self._templates[template_name],dict) else {}
......@@ -72,7 +97,7 @@ class Packman:
Returns
-------
:obj: `PackerTemplate`
:class:`PackerTemplate`
The template object used by packman to build the manifest.json file.
"""
......@@ -147,15 +172,11 @@ class Packman:
Returns
-------
List of str
list
Returns the hierarchy of templates from the one with no parent to the ones with parents.
"""
if selected_templates is None:
templates = set(self._templates.keys())
else:
# Filter out the image names not present in the yaml file
templates = set([template for template in selected_templates if template in self._templates])
templates = self.get_templates_selection(selected_templates)
config_hierarchy = []
for template in templates:
......@@ -227,11 +248,10 @@ class Packman:
If True packer will be run from the generated manifest.json files.
"""
if selected_templates is None:
templates = self._templates.keys()
else:
# Filter out the image names not present in the yaml file
templates = [template for template in selected_templates if template in self._templates]
templates = self.get_templates_selection(selected_templates)
if not templates:
raise RuntimeError("Invalid or empty template selection")
# Loop over the selected templates
for template_name in templates:
......@@ -246,6 +266,6 @@ class Packman:
template.set_parent(parent_template)
# Dump the template
ouput_file = os.path.join(self._templates_base_dir,template_name,"manifest.json")
template.dump(ouput_file,**kwargs)
output_file = os.path.join(self._templates_base_dir,template_name,"manifest.json")
template.dump(output_file,**kwargs)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment