Templating

class narrenschiff.templating.ChestVars(template_directory)[source]

Load chest files.

load_vars()[source]

Load variables.

Returns

Variables to be used for template rendering

Return type

dict

class narrenschiff.templating.PlainVars(template_directory)[source]

Load cleartext variable files.

class narrenschiff.templating.SecretmapVars(template_directory)[source]

Load secretmap files.

class narrenschiff.templating.Template(*args, **kwargs)[source]

Load and manipulate templates and template environment.

clear_templates()[source]

Delete all templates from the /tmp directory.

Returns

Void

Return type

None

find_duplicates(values)[source]

Find duplicate keys.

Parameters

values (list of str) – List of keys from var and chest files.

Returns

List of duplicates

Return type

list of str

load_vars()[source]

Load variables.

Returns

Variables to be used for template rendering

Return type

dict

This is the order in which files containing variables are loaded:

  1. Load vars.yaml if it exists

  2. Load all files from the vars/ directory if it exists

  3. Load and decrypt all variables from chest.yaml

  4. Load all files from the chest/ directory if it exists

  5. Load all variables from secretmap.yaml

  6. Merge all files

Important: Files must not contain duplicate variable names!

render(path)[source]

Render template on the given path.

Parameters

path (str) – Path to the template file

Returns

Rendered template

Return type

str

render_all_files()[source]

Render all templates from the directory.

Returns

Void

Return type

None

Templates are copied to /tmp and location of rendered templates is saved in self.tmp.

set_course(path)[source]

Prepare Jinja2 templating environment.

Parameters

path (str) – Path of the tasks.yaml file

Returns

Void

Return type

None

Directory containing the course (e.g. tasks.yaml) file will be the directory from where the templates are taken to be rendered.

exception narrenschiff.templating.TemplateException[source]

Use for exceptions regarding template manipulation.

class narrenschiff.templating.Vars(name, template_directory)[source]

Manipulate files containing variables.

load_vars()[source]

Load variables.

Returns

Variables to be used for template rendering

Return type

dict

exception narrenschiff.templating.VarsFileNotFoundError[source]

Missing files containing variables.