mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 13:13:49 +00:00
fix templatenotfound for #226
This commit is contained in:
@@ -209,6 +209,7 @@ def cmd_compare(o, tmp):
|
||||
t = Templategen(base=o.dotpath, variables=o.variables,
|
||||
func_file=o.func_file, filter_file=o.filter_file,
|
||||
debug=o.debug)
|
||||
tvars = t.add_tmp_vars()
|
||||
inst = Installer(create=o.create, backup=o.backup,
|
||||
dry=o.dry, base=o.dotpath,
|
||||
workdir=o.workdir, debug=o.debug,
|
||||
@@ -217,6 +218,11 @@ def cmd_compare(o, tmp):
|
||||
comp = Comparator(diff_cmd=o.diff_command, debug=o.debug)
|
||||
|
||||
for dotfile in selected:
|
||||
# add dotfile variables
|
||||
t.restore_vars(tvars)
|
||||
newvars = dotfile.get_dotfile_variables()
|
||||
t.add_tmp_vars(newvars=newvars)
|
||||
|
||||
if o.debug:
|
||||
LOG.dbg('comparing {}'.format(dotfile))
|
||||
src = dotfile.src
|
||||
|
||||
@@ -6,7 +6,8 @@ jinja2 template generator
|
||||
"""
|
||||
|
||||
import os
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from jinja2 import Environment, FileSystemLoader, \
|
||||
ChoiceLoader, FunctionLoader, TemplateNotFound
|
||||
|
||||
# local imports
|
||||
import dotdrop.utils as utils
|
||||
@@ -35,7 +36,9 @@ class Templategen:
|
||||
self.base = base.rstrip(os.sep)
|
||||
self.debug = debug
|
||||
self.log = Logger()
|
||||
loader = FileSystemLoader(self.base)
|
||||
loader1 = FileSystemLoader(self.base)
|
||||
loader2 = FunctionLoader(self._template_loader)
|
||||
loader = ChoiceLoader([loader1, loader2])
|
||||
self.env = Environment(loader=loader,
|
||||
trim_blocks=True, lstrip_blocks=True,
|
||||
keep_trailing_newline=True,
|
||||
@@ -142,6 +145,15 @@ class Templategen:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _template_loader(self, relpath):
|
||||
"""manually load template when outside of base"""
|
||||
path = os.path.join(self.base, relpath)
|
||||
if not os.path.exists(path):
|
||||
raise TemplateNotFound(path)
|
||||
with open(path, 'r') as f:
|
||||
content = f.read()
|
||||
return content
|
||||
|
||||
def _handle_text_file(self, src):
|
||||
"""write text to file"""
|
||||
template_rel_path = os.path.relpath(src, self.base)
|
||||
|
||||
Reference in New Issue
Block a user