Ejemplo n.º 1
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)

        base = self._get_defaults()
        with util.open_file(self.molecule_file) as stream:
            try:
                interpolated_config = i.interpolate(stream.read())
                base = self.merge_dicts(base,
                                        util.safe_load(interpolated_config))
            except interpolation.InvalidInterpolation as e:
                msg = ("parsing config file '{}'.\n\n"
                       '{}\n{}'.format(self.molecule_file, e.place, e.string))
                util.sysexit_with_message(msg)

        schema.validate(base)

        return base
Ejemplo n.º 2
0
    def _interpolate(self, stream, env, keep_string):
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)

        try:
            return i.interpolate(stream, keep_string)
        except interpolation.InvalidInterpolation as e:
            msg = ("parsing config file '{}'.\n\n"
                   '{}\n{}'.format(self.molecule_file, e.place, e.string))
            util.sysexit_with_message(msg)
Ejemplo n.º 3
0
    def _interpolate(self, stream: str, env: MutableMapping, keep_string: str) -> str:
        env = set_env_from_file(env, self.env_file)

        i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)

        try:
            return i.interpolate(stream, keep_string)
        except interpolation.InvalidInterpolation as e:
            msg = "parsing config file '{}'.\n\n" "{}\n{}".format(
                self.molecule_file, e.place, e.string
            )
            util.sysexit_with_message(msg)
        return ""
Ejemplo n.º 4
0
def from_yaml(data):
    """
    Interpolate the provided data and return a dict.

    Currently, this is used to reinterpolate the `molecule.yml` inside an
    Ansible playbook.  If there were any interpolation errors, they would
    have been found and raised earlier.

    :return: dict
    """
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                   os.environ)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Ejemplo n.º 5
0
    def _combine(self):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)

        base = self._get_defaults()
        with open(self.molecule_file, 'r') as stream:
            interpolated_config = i.interpolate(stream.read())
            base = self.merge_dicts(base, util.safe_load(interpolated_config))

        return base
Ejemplo n.º 6
0
def from_yaml(data):
    """
    Interpolate the provided data and return a dict.

    Currently, this is used to reinterpolate the `molecule.yml` inside an
    Ansible playbook.  If there were any interpolation errors, they would
    have been found and raised earlier.

    :return: dict
    """
    molecule_env_file = os.environ['MOLECULE_ENV_FILE']

    env = os.environ.copy()
    env = config.set_env_from_file(env, molecule_env_file)

    i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Ejemplo n.º 7
0
def coerce_env(env, keep_string, v):
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults, env)

    return i.interpolate(v, keep_string)
Ejemplo n.º 8
0
def _instance(_mock_env):
    return interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                      _mock_env)
Ejemplo n.º 9
0
def from_yaml(data):
    i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                   os.environ)
    interpolated_data = i.interpolate(data)

    return util.safe_load(interpolated_data)
Ejemplo n.º 10
0
def interpolator_instance(mock_env):
    return interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                      mock_env).interpolate
Ejemplo n.º 11
0
        """
        env = util.merge_dicts(os.environ.copy(), self.env)

        return self._combine(env=env)

    def _combine(self, env=os.environ, keep_string=None):
        """
        Perform a prioritized recursive merge of the `molecule_file` with
        defaults, interpolate the result with environment variables, and
        returns a new dict.

        :return: dict
        """
<<<<<<< HEAD
<<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py
        i = interpolation.Interpolator(interpolation.TemplateWithDefaults,
                                       os.environ)
=======
=======
<<<<<<< HEAD:molecule/config.py
>>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac
        defaults = self._get_defaults()
        base_config = self.args.get('base_config')
        if base_config and os.path.exists(base_config):
            with util.open_file(base_config) as stream:
                s = stream.read()
                self._preflight(s)
                interpolated_config = self._interpolate(s, env, keep_string)
                defaults = util.merge_dicts(
                    defaults, util.safe_load(interpolated_config))
<<<<<<< HEAD
>>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/config.py