You're reading an old version of this documentation. If you want up-to-date information, please have a look at v0.8.2.

snl_d3d_cec_verify.copier package

snl_d3d_cec_verify.copier.copy(src_path, dst_path, data=None, exist_ok=False)

Recursively copy and populate a source folder containing templated or non-templated files to the given destination folder.

Templates are rendered using the jinja2.Template.render() method. For example:

>>> import tempfile
>>> from pathlib import Path
>>> with tempfile.TemporaryDirectory() as tmpdirname:
...     template = Path(tmpdirname) / "input"
...     template.mkdir()
...     p = template / "hello.txt"
...     _ = p.write_text("{{ x }}\n")
...     result = Path(tmpdirname) / "output"
...     copy(template, result, {"x": "Hello!"})
...     print((result / "hello.txt").read_text())
Hello!
Parameters:
  • src_path (Union[str, Path]) – path to the folder containing the source files

  • dst_path (Union[str, Path]) – path to the destination folder

  • data (Optional[Dict[str, Any]]) – dictionary containing the data used to populate the template files. The keys are the variable names used in the template with the values being the replacement values.

  • exist_ok (bool) – if True, allow an existing path to be overwritten, defaults to False

Raises:
  • ValueError – if the given CaseStudy object is not length one or if template_path does not exist

  • FileExistsError – if the project path exists, but exist_ok is False

  • RuntimeError – if trying to remove a non-basic file or folder