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

fix bug for #204

This commit is contained in:
deadc0de6
2020-01-21 09:03:24 +01:00
parent d242742d24
commit 53dfbc8aa3
3 changed files with 66 additions and 3 deletions

View File

@@ -618,13 +618,26 @@ class CfgYaml:
self.log.warn(err)
return
sub = CfgYaml(path, profile=self.profile, debug=self.debug)
# settings is ignored
# settings are ignored from external file
# except for filter_file and func_file
self.settings[Settings.key_func_file] += [
self._norm_path(func_file)
for func_file in sub.settings[Settings.key_func_file]
]
self.settings[Settings.key_filter_file] += [
self._norm_path(func_file)
for func_file in sub.settings[Settings.key_filter_file]
]
# merge top entries
self.dotfiles = self._merge_dict(self.dotfiles, sub.dotfiles)
self.profiles = self._merge_dict(self.profiles, sub.profiles)
self.actions = self._merge_dict(self.actions, sub.actions)
self.trans_r = self._merge_dict(self.trans_r, sub.trans_r)
self.trans_w = self._merge_dict(self.trans_w, sub.trans_w)
self._clear_profile_vars(sub.variables)
if self.debug:
self.log.dbg('add import_configs var: {}'.format(sub.variables))
self.variables = self._merge_dict(sub.variables, self.variables)

View File

@@ -53,9 +53,11 @@ tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
#echo "dotfile destination: ${tmpd}"
filter_file=`mktemp`
filter_file2=`mktemp`
filter_file3=`mktemp`
# create the config file
cfg="${tmps}/config.yaml"
cfgext="${tmps}/ext.yaml"
cat > ${cfg} << _EOF
config:
@@ -65,6 +67,8 @@ config:
filter_file:
- ${filter_file}
- ${filter_file2}
import_configs:
- ${cfgext}
dotfiles:
f_abc:
dst: ${tmpd}/abc
@@ -76,6 +80,17 @@ profiles:
_EOF
#cat ${cfg}
cat > ${cfgext} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
filter_file:
- ${filter_file3}
profiles:
dotfiles:
_EOF
cat << _EOF > ${filter_file}
def filter1(arg1):
return "filtered"
@@ -88,6 +103,11 @@ def filter3(integer):
return str(int(integer) - 10)
_EOF
cat << _EOF > ${filter_file3}
def filter_ext(arg1):
return "external"
_EOF
# create the dotfile
echo "this is the test dotfile" > ${tmps}/dotfiles/abc
@@ -95,6 +115,7 @@ echo "this is the test dotfile" > ${tmps}/dotfiles/abc
echo "{{@@ "abc" | filter1 @@}}" >> ${tmps}/dotfiles/abc
echo "{{@@ "arg1" | filter2('arg2') @@}}" >> ${tmps}/dotfiles/abc
echo "{{@@ "13" | filter3() @@}}" >> ${tmps}/dotfiles/abc
echo "{{@@ "something" | filter_ext() @@}}" >> ${tmps}/dotfiles/abc
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
@@ -104,9 +125,13 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
grep '^filtered$' ${tmpd}/abc >/dev/null
grep '^arg2$' ${tmpd}/abc >/dev/null
grep '^3$' ${tmpd}/abc >/dev/null
grep '^external$' ${tmpd}/abc >/dev/null
set +e
grep '^something$' ${tmpd}/abc >/dev/null && exit 1
set -e
## CLEANING
rm -rf ${tmps} ${tmpd} ${filter_file} ${filter_file2}
rm -rf ${tmps} ${tmpd} ${filter_file} ${filter_file2} ${filter_file3}
echo "OK"
exit 0

View File

@@ -53,9 +53,11 @@ tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
#echo "dotfile destination: ${tmpd}"
func_file=`mktemp`
func_file2=`mktemp`
func_file3=`mktemp`
# create the config file
cfg="${tmps}/config.yaml"
cfgext="${tmps}/ext.yaml"
cat > ${cfg} << _EOF
config:
@@ -65,6 +67,8 @@ config:
func_file:
- ${func_file}
- ${func_file2}
import_configs:
- ${cfgext}
dotfiles:
f_abc:
dst: ${tmpd}/abc
@@ -76,6 +80,17 @@ profiles:
_EOF
#cat ${cfg}
cat > ${cfgext} << _EOF
config:
backup: true
create: true
dotpath: dotfiles
func_file:
- ${func_file3}
dotfiles:
profiles:
_EOF
cat << _EOF > ${func_file}
def func1(something):
if something:
@@ -88,6 +103,11 @@ def func2(inp):
return not inp
_EOF
cat << _EOF > ${func_file3}
def func3(inp):
return "external"
_EOF
# create the dotfile
echo "this is the test dotfile" > ${tmps}/dotfiles/abc
@@ -108,6 +128,10 @@ echo "{%@@ if func2(False) @@%}" >> ${tmps}/dotfiles/abc
echo "yes" >> ${tmps}/dotfiles/abc
echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc
echo "{%@@ if func3("whatever") == "external" @@%}" >> ${tmps}/dotfiles/abc
echo "externalok" >> ${tmps}/dotfiles/abc
echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
@@ -116,12 +140,13 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
grep '^this should exist$' ${tmpd}/abc >/dev/null
grep '^this should exist too$' ${tmpd}/abc >/dev/null
grep '^yes$' ${tmpd}/abc >/dev/null
grep '^externalok$' ${tmpd}/abc >/dev/null
set +e
grep '^nope$' ${tmpd}/abc >/dev/null && exit 1
set -e
## CLEANING
rm -rf ${tmps} ${tmpd} ${func_file} ${func_file2}
rm -rf ${tmps} ${tmpd} ${func_file} ${func_file2} ${func_file3}
echo "OK"
exit 0