Commit 2146af1c authored by Eric Pellegrini's avatar Eric Pellegrini

updated docstrings and stub files

parent 9b63ba84
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
import pprint import pprint
import yaml import yaml
from typing import List from typing import Dict, List
class PackerTemplate: class PackerTemplate:
"""This class implements one packer template. """This class implements one packer template.
...@@ -55,8 +55,13 @@ class PackerTemplate: ...@@ -55,8 +55,13 @@ class PackerTemplate:
self._load_packages(packages) self._load_packages(packages)
def _update_builder(self, builder): def _update_builder(self, builder: Dict[str,str]):
"""Update a builder. """Update some fields of a builder.
Parameters
----------
builder: dict
The builder to update.
""" """
builder["output_directory"] = "builds" builder["output_directory"] = "builds"
...@@ -70,7 +75,17 @@ class PackerTemplate: ...@@ -70,7 +75,17 @@ class PackerTemplate:
# For convenience set the vm name with a fixed standardized value # For convenience set the vm name with a fixed standardized value
builder["vm_name"] = "{}-{}".format(self._name,builder["type"]) builder["vm_name"] = "{}-{}".format(self._name,builder["type"])
def _update_provisioner(self, provisioner, base_dir): def _update_provisioner(self, provisioner : Dict[str,str], base_dir : str):
"""Update some fields of a provisioner.
Parameters
----------
provisioner: dict
The provisioner to update.
base_dir: str
The base directory for this provisioner.
"""
if not provisioner["type"] in ["file","shell"]: if not provisioner["type"] in ["file","shell"]:
return return
...@@ -203,14 +218,14 @@ class PackerTemplate: ...@@ -203,14 +218,14 @@ class PackerTemplate:
fin = open(manifest_file, "r") fin = open(manifest_file, "r")
# If the manifest does not exist, the provisioners list is set to an empty list # If the manifest does not exist, the provisioners list is set to an empty list
except FileNotFoundError: except FileNotFoundError:
manifest_data = [] manifest_data: List = []
else: else:
root_node = yaml.safe_load(fin) root_node = yaml.safe_load(fin)
manifest_data = root_node["provisioners"] manifest_data = root_node["provisioners"]
# Loop over the provisioners list and update when necessary relative paths with absolute one for packer to run correctly # Loop over the provisioners list and update when necessary relative paths with absolute one for packer to run correctly
for provisioner in manifest_data: for provisioner in manifest_data:
self._update_provisioner(provisioner,package_dir,self._name) self._update_provisioner(provisioner,os.path.join(package_dir,self._name))
# Extend the current provisioners list with the ones of the selected packages # Extend the current provisioners list with the ones of the selected packages
self._provisioners.extend(manifest_data) self._provisioners.extend(manifest_data)
...@@ -253,7 +268,7 @@ class PackerTemplate: ...@@ -253,7 +268,7 @@ class PackerTemplate:
"""Returns the string representation for this :class:`PackerTemplate`. """Returns the string representation for this :class:`PackerTemplate`.
""" """
d = collections.OrderedDict() d : collections.OrderedDict = collections.OrderedDict()
d["description"] = self._description d["description"] = self._description
d["variables"] = self._variables d["variables"] = self._variables
d["builders"] = self._builders d["builders"] = self._builders
......
...@@ -105,7 +105,7 @@ class Packman: ...@@ -105,7 +105,7 @@ class Packman:
fin = open(manifest_file, "r") fin = open(manifest_file, "r")
# If the file does not exist, the manifest contents is just an empty dict # If the file does not exist, the manifest contents is just an empty dict
except FileNotFoundError: except FileNotFoundError:
manifest_data = {} manifest_data : Dict[str,str] = {}
else: else:
manifest_data = yaml.safe_load(fin) manifest_data = yaml.safe_load(fin)
......
from typing import Any, List from typing import Any, List
class PackerTemplate: class PackerTemplate:
def __init__(self, name: str, yaml_node: dict, packages: List[str]) -> None: ... def __init__(self, name: str, yaml_node: dict, packages: List[str], packages_base_dir: str, templates_base_dir: str) -> None: ...
@property @property
def builders(self) -> list: ... def builders(self) -> list: ...
@property @property
......
from .PackerTemplate import PackerTemplate as PackerTemplate
from typing import Any, List, Optional from typing import Any, List, Optional
class Packman: class Packman:
def __init__(self, input_file: str, templates_base_dir: str) -> None: ... def __init__(self, input_file: str, templates_base_dir: Optional[str]=..., packages_base_dir: Optional[str]=...) -> None: ...
def get_templates_selection(self, selected_templates: Optional[Any]=...) -> Any: ... def get_templates_selection(self, selected_templates: Optional[Any] = ...): ...
def get_template(self, template_name: Any) -> Any: ... def get_template(self, template_name: Any): ...
def run(self, selected_templates: Optional[List[str]]=..., log: Optional[bool]=...) -> Any: ... def run(self, selected_templates: Optional[List[str]]=..., log: Optional[bool]=..., key_rate: Optional[int]=...) -> Any: ...
def build(self, selected_templates: Optional[List[str]]=..., **kwargs: Any) -> Any: ... def build(self, selected_templates: Optional[List[str]]=..., **kwargs: Any) -> Any: ...
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