From a4a831195ebac38b2f7c7ce2202e46b17a1859b5 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 10 Jul 2019 13:39:02 +0200 Subject: [PATCH] fix dotfile src/dst not expanded with ext variables (#177) --- dotdrop/cfg_yaml.py | 21 ++++++++++++--------- tests-ng/extvariables.sh | 10 ++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/dotdrop/cfg_yaml.py b/dotdrop/cfg_yaml.py index b251af8..2bfbf0a 100644 --- a/dotdrop/cfg_yaml.py +++ b/dotdrop/cfg_yaml.py @@ -214,11 +214,23 @@ class CfgYaml: def _resolve_dotfile_paths(self): """resolve dotfile paths""" + t = Templategen(variables=self.variables) + for dotfile in self.dotfiles.values(): + # src src = dotfile[self.key_dotfile_src] + new = t.generate_string(src) + if new != src and self.debug: + self.log.dbg('dotfile: {} -> {}'.format(src, new)) + src = new src = os.path.join(self.settings[self.key_settings_dotpath], src) dotfile[self.key_dotfile_src] = self._norm_path(src) + # dst dst = dotfile[self.key_dotfile_dst] + new = t.generate_string(dst) + if new != dst and self.debug: + self.log.dbg('dotfile: {} -> {}'.format(dst, new)) + dst = new dotfile[self.key_dotfile_dst] = self._norm_path(dst) def _rec_resolve_vars(self, variables): @@ -292,15 +304,6 @@ class CfgYaml: """template any needed parts of the config""" t = Templategen(variables=self.variables) - # dotfiles src/dst/actions keys - for k, v in self.dotfiles.items(): - # src - src = v.get(self.key_dotfile_src) - v[self.key_dotfile_src] = t.generate_string(src) - # dst - dst = v.get(self.key_dotfile_dst) - v[self.key_dotfile_dst] = t.generate_string(dst) - # import_actions new = [] entries = self.settings.get(self.key_import_actions, []) diff --git a/tests-ng/extvariables.sh b/tests-ng/extvariables.sh index 3958c56..d51814d 100755 --- a/tests-ng/extvariables.sh +++ b/tests-ng/extvariables.sh @@ -78,10 +78,14 @@ dotfiles: f_abc: dst: ${tmpd}/abc src: abc + f_def: + dst: ${tmpd}/{{@@ theprofile @@}} + src: def profiles: p1: dotfiles: - f_abc + - f_def variables: varx: profvarx provar: provar @@ -107,6 +111,8 @@ echo "evar1: {{@@ evar1 @@}}" >> ${tmps}/dotfiles/abc echo "provar: {{@@ provar @@}}" >> ${tmps}/dotfiles/abc echo "theprofile: {{@@ theprofile @@}}" >> ${tmps}/dotfiles/abc +echo "theprofile: {{@@ theprofile @@}}" > ${tmps}/dotfiles/def + #cat ${tmps}/dotfiles/abc # install @@ -123,6 +129,10 @@ grep '^evar1: extevar1' ${tmpd}/abc >/dev/null grep '^provar: provar' ${tmpd}/abc >/dev/null grep '^theprofile: p1' ${tmpd}/abc >/dev/null +# check def +[ ! -e ${tmpd}/p1 ] && echo "def not created" && exit 1 +grep '^theprofile: p1' ${tmpd}/p1 >/dev/null + rm -f ${tmpd}/abc #cat ${tmpd}/abc