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

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

Context manaager for recursively copying and populating a source folder containing templated or non-templated files to the given destination folder.

Templates are rendered using the jinja2.Template.render() method. The template’s directory structure is created on entering the context and the template data dictionary is yielded. This allows generation of data, which requires the directory structure to exist, before writing to the template files. The template files are then written when the context is closed. 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"
...     with copy_after(template, result) as data:
...          data["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

Yields:

template data dictionary

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

Return type:

Generator[Dict[str, Any], None, None]