mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 18:59:16 +00:00
Merge pull request #227 from deadc0de6/templatenotfound
Templatenotfound
This commit is contained in:
@@ -209,6 +209,7 @@ def cmd_compare(o, tmp):
|
|||||||
t = Templategen(base=o.dotpath, variables=o.variables,
|
t = Templategen(base=o.dotpath, variables=o.variables,
|
||||||
func_file=o.func_file, filter_file=o.filter_file,
|
func_file=o.func_file, filter_file=o.filter_file,
|
||||||
debug=o.debug)
|
debug=o.debug)
|
||||||
|
tvars = t.add_tmp_vars()
|
||||||
inst = Installer(create=o.create, backup=o.backup,
|
inst = Installer(create=o.create, backup=o.backup,
|
||||||
dry=o.dry, base=o.dotpath,
|
dry=o.dry, base=o.dotpath,
|
||||||
workdir=o.workdir, debug=o.debug,
|
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)
|
comp = Comparator(diff_cmd=o.diff_command, debug=o.debug)
|
||||||
|
|
||||||
for dotfile in selected:
|
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:
|
if o.debug:
|
||||||
LOG.dbg('comparing {}'.format(dotfile))
|
LOG.dbg('comparing {}'.format(dotfile))
|
||||||
src = dotfile.src
|
src = dotfile.src
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ jinja2 template generator
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader, \
|
||||||
|
ChoiceLoader, FunctionLoader, TemplateNotFound
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import dotdrop.utils as utils
|
import dotdrop.utils as utils
|
||||||
@@ -35,7 +36,9 @@ class Templategen:
|
|||||||
self.base = base.rstrip(os.sep)
|
self.base = base.rstrip(os.sep)
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.log = Logger()
|
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,
|
self.env = Environment(loader=loader,
|
||||||
trim_blocks=True, lstrip_blocks=True,
|
trim_blocks=True, lstrip_blocks=True,
|
||||||
keep_trailing_newline=True,
|
keep_trailing_newline=True,
|
||||||
@@ -142,6 +145,16 @@ class Templategen:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _template_loader(self, relpath):
|
||||||
|
"""manually load template when outside of base"""
|
||||||
|
path = os.path.join(self.base, relpath)
|
||||||
|
path = os.path.normpath(path)
|
||||||
|
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):
|
def _handle_text_file(self, src):
|
||||||
"""write text to file"""
|
"""write text to file"""
|
||||||
template_rel_path = os.path.relpath(src, self.base)
|
template_rel_path = os.path.relpath(src, self.base)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)"
|
|||||||
# the dotfile source
|
# the dotfile source
|
||||||
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
tmps=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||||
mkdir -p ${tmps}/dotfiles
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles-other
|
||||||
# the dotfile destination
|
# the dotfile destination
|
||||||
tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ cat > ${cfg2} << _EOF
|
|||||||
config:
|
config:
|
||||||
backup: true
|
backup: true
|
||||||
create: true
|
create: true
|
||||||
dotpath: dotfiles
|
dotpath: dotfiles-other
|
||||||
dotfiles:
|
dotfiles:
|
||||||
f_def:
|
f_def:
|
||||||
dst: ${tmpd}/def
|
dst: ${tmpd}/def
|
||||||
@@ -98,10 +99,14 @@ dotfiles:
|
|||||||
f_ghi:
|
f_ghi:
|
||||||
dst: ${tmpd}/ghi
|
dst: ${tmpd}/ghi
|
||||||
src: ghi
|
src: ghi
|
||||||
|
f_asub:
|
||||||
|
dst: ${tmpd}/subdir/sub/asub
|
||||||
|
src: subdir/sub/asub
|
||||||
profiles:
|
profiles:
|
||||||
p2:
|
p2:
|
||||||
dotfiles:
|
dotfiles:
|
||||||
- f_def
|
- f_def
|
||||||
|
- f_asub
|
||||||
psubsub:
|
psubsub:
|
||||||
dotfiles:
|
dotfiles:
|
||||||
- f_sub
|
- f_sub
|
||||||
@@ -110,10 +115,23 @@ _EOF
|
|||||||
# create the source
|
# create the source
|
||||||
mkdir -p ${tmps}/dotfiles/
|
mkdir -p ${tmps}/dotfiles/
|
||||||
echo "abc" > ${tmps}/dotfiles/abc
|
echo "abc" > ${tmps}/dotfiles/abc
|
||||||
echo "def" > ${tmps}/dotfiles/def
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/abc
|
||||||
echo "ghi" > ${tmps}/dotfiles/ghi
|
|
||||||
|
echo "def" > ${tmps}/dotfiles-other/def
|
||||||
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/def
|
||||||
|
|
||||||
|
echo "ghi" > ${tmps}/dotfiles-other/ghi
|
||||||
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/ghi
|
||||||
|
|
||||||
echo "zzz" > ${tmps}/dotfiles/zzz
|
echo "zzz" > ${tmps}/dotfiles/zzz
|
||||||
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/zzz
|
||||||
|
|
||||||
echo "sub" > ${tmps}/dotfiles/sub
|
echo "sub" > ${tmps}/dotfiles/sub
|
||||||
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles/sub
|
||||||
|
|
||||||
|
mkdir -p ${tmps}/dotfiles-other/subdir/sub
|
||||||
|
echo "subsub" > ${tmps}/dotfiles-other/subdir/sub/asub
|
||||||
|
echo "{{@@ _dotfile_abs_dst @@}}" >> ${tmps}/dotfiles-other/subdir/sub/asub
|
||||||
|
|
||||||
# install
|
# install
|
||||||
cd ${ddpath} | ${bin} files -c ${cfg1} -p p0 -V | grep f_def
|
cd ${ddpath} | ${bin} files -c ${cfg1} -p p0 -V | grep f_def
|
||||||
@@ -123,6 +141,39 @@ cd ${ddpath} | ${bin} files -c ${cfg1} -p p3 -V | grep f_zzz
|
|||||||
cd ${ddpath} | ${bin} files -c ${cfg1} -p pup -V | grep f_sub
|
cd ${ddpath} | ${bin} files -c ${cfg1} -p pup -V | grep f_sub
|
||||||
cd ${ddpath} | ${bin} files -c ${cfg1} -p psubsub -V | grep f_sub
|
cd ${ddpath} | ${bin} files -c ${cfg1} -p psubsub -V | grep f_sub
|
||||||
|
|
||||||
|
# test compare too
|
||||||
|
cd ${ddpath} | ${bin} install -c ${cfg1} -p p2 -V
|
||||||
|
cd ${ddpath} | ${bin} compare -c ${cfg1} -p p2 -V
|
||||||
|
|
||||||
|
# test with non-existing dotpath this time
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
cat > ${cfg1} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
import_configs:
|
||||||
|
- ${cfg2}
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
cat > ${cfg2} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles-other
|
||||||
|
dotfiles:
|
||||||
|
f_asub:
|
||||||
|
dst: ${tmpd}/subdir/sub/asub
|
||||||
|
src: subdir/sub/asub
|
||||||
|
profiles:
|
||||||
|
p2:
|
||||||
|
dotfiles:
|
||||||
|
- f_asub
|
||||||
|
_EOF
|
||||||
|
cd ${ddpath} | ${bin} install -c ${cfg1} -p p2 -V
|
||||||
|
cd ${ddpath} | ${bin} compare -c ${cfg1} -p p2 -V
|
||||||
|
|
||||||
## CLEANING
|
## CLEANING
|
||||||
rm -rf ${tmps} ${tmpd}
|
rm -rf ${tmps} ${tmpd}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user