1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 22:39:43 +00:00

Add exists_in_path jinja helper function

The function is a wrapper around `shutil.which` that allows to check for
an executable in the OS's PATH within templates.
This commit is contained in:
Lucas Schwiderski
2019-03-24 14:37:15 +01:00
parent 90f9ced746
commit 725b265651
2 changed files with 7 additions and 0 deletions

View File

@@ -6,8 +6,14 @@ jinja2 helper methods
"""
import os
import shutil
def exists(path):
"""return true when path exists"""
return os.path.exists(os.path.expandvars(path))
def exists_in_path(name, path=None):
"""return true when executable exists in os path"""
return shutil.which(name, os.F_OK | os.X_OK, path) is not None

View File

@@ -49,6 +49,7 @@ class Templategen:
self.env.globals['header'] = self._header
# adding helper methods
self.env.globals['exists'] = jhelpers.exists
self.env.globals['exists_in_path'] = jhelpers.exists_in_path
def generate(self, src):
"""render template from path"""