MCPcopy
hub / github.com/saltstack/salt / _render

Function _render

salt/client/ssh/wrapper/cp.py:859–878  ·  view source on GitHub ↗

Render :param:`contents` into a literal pathname by writing it to a temp file, rendering that file, and returning the result.

(contents)

Source from the content-addressed store, hash-verified

857 kwargs["saltenv"] = saltenv
858
859 def _render(contents):
860 """
861 Render :param:`contents` into a literal pathname by writing it to a
862 temp file, rendering that file, and returning the result.
863 """
864 # write out path to temp file
865 tmp_path_fn = salt.utils.files.mkstemp()
866 with salt.utils.files.fopen(tmp_path_fn, "w+") as fp_:
867 fp_.write(salt.utils.stringutils.to_str(contents))
868 data = salt.utils.templates.TEMPLATE_REGISTRY[template](
869 tmp_path_fn, to_str=True, **kwargs
870 )
871 salt.utils.files.safe_rm(tmp_path_fn)
872 if not data["result"]:
873 # Failed to render the template
874 raise CommandExecutionError(
875 "Failed to render file path with error: {}".format(data["data"])
876 )
877 else:
878 return data["data"]
879
880 path = _render(path)
881 dest = _render(dest)

Callers 1

_render_filenamesFunction · 0.70

Calls 3

formatMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected