mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-14 19:22:26 +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:
@@ -6,8 +6,14 @@ jinja2 helper methods
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def exists(path):
|
def exists(path):
|
||||||
"""return true when path exists"""
|
"""return true when path exists"""
|
||||||
return os.path.exists(os.path.expandvars(path))
|
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
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Templategen:
|
|||||||
self.env.globals['header'] = self._header
|
self.env.globals['header'] = self._header
|
||||||
# adding helper methods
|
# adding helper methods
|
||||||
self.env.globals['exists'] = jhelpers.exists
|
self.env.globals['exists'] = jhelpers.exists
|
||||||
|
self.env.globals['exists_in_path'] = jhelpers.exists_in_path
|
||||||
|
|
||||||
def generate(self, src):
|
def generate(self, src):
|
||||||
"""render template from path"""
|
"""render template from path"""
|
||||||
|
|||||||
Reference in New Issue
Block a user