diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-27 11:46:51 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-27 11:51:53 +0100 |
commit | 2bf12b579e083a8b527d3202ced365b8adf32625 (patch) | |
tree | bce48dcc8aede9d3578c374f86a7932319de58e0 /python/vyos/template.py | |
parent | cff252427c1aa9c8fe0cf7a305c2a5a294c71773 (diff) | |
download | vyos-1x-2bf12b579e083a8b527d3202ced365b8adf32625.tar.gz vyos-1x-2bf12b579e083a8b527d3202ced365b8adf32625.zip |
template: T2388: move mkdir/chmod/chown within render()
Diffstat (limited to 'python/vyos/template.py')
-rw-r--r-- | python/vyos/template.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 6c73ce753..e4b253ed3 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -19,6 +19,7 @@ from jinja2 import Environment from jinja2 import FileSystemLoader from vyos.defaults import directories +from vyos.util import chmod, chown, makedir # reuse the same Environment to improve performance @@ -32,7 +33,7 @@ _templates_mem = { } -def render(destination, template, content, trim_blocks=False, formater=None): +def render(destination, template, content, trim_blocks=False, formater=None, permission=None, user=None, group=None): """ render a template from the template directory, it will raise on any errors destination: the file where the rendered template must be saved @@ -46,6 +47,10 @@ def render(destination, template, content, trim_blocks=False, formater=None): (recovering the load time and overhead caused by having the file out of the code) """ + # Create the directory if it does not exists + folder = os.path.dirname(destination) + makedir(folder, user, group) + # Setup a renderer for the given template # This is cached and re-used for performance if template not in _templates_mem[trim_blocks]: @@ -63,3 +68,6 @@ def render(destination, template, content, trim_blocks=False, formater=None): # Write client config file with open(destination, 'w') as f: f.write(content) + + chmod(destination, permission) + chown(destination, user, group) |