mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 18:09:17 +00:00
Merge pull request #248 from davla/bug246
Fixing profile variables from included files
This commit is contained in:
@@ -521,21 +521,17 @@ class CfgYaml:
|
|||||||
returns dotfiles, actions, variables, dynvariables
|
returns dotfiles, actions, variables, dynvariables
|
||||||
"""
|
"""
|
||||||
this_profile = self.profiles[profile]
|
this_profile = self.profiles[profile]
|
||||||
# the profiles included by the selected profile
|
|
||||||
included = []
|
|
||||||
if self.profile and self.profile in self.profiles:
|
|
||||||
included = self.profiles[self.profile] \
|
|
||||||
.get(self.key_profile_include, []) or []
|
|
||||||
|
|
||||||
# considered profile content
|
# considered profile content
|
||||||
dotfiles = this_profile.get(self.key_profile_dotfiles, []) or []
|
dotfiles = this_profile.get(self.key_profile_dotfiles, []) or []
|
||||||
actions = this_profile.get(self.key_profile_actions, []) or []
|
actions = this_profile.get(self.key_profile_actions, []) or []
|
||||||
includes = this_profile.get(self.key_profile_include, []) or []
|
includes = this_profile.get(self.key_profile_include, []) or []
|
||||||
pvars = this_profile.get(self.key_profile_variables, []) or []
|
pvars = this_profile.get(self.key_profile_variables, {}) or {}
|
||||||
pdvars = this_profile.get(self.key_profile_dvariables, []) or []
|
pdvars = this_profile.get(self.key_profile_dvariables, {}) or {}
|
||||||
if not includes:
|
if not includes:
|
||||||
# nothing to include
|
# nothing to include
|
||||||
return dotfiles, actions, pvars, pdvars
|
return dotfiles, actions, pvars, pdvars
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('{} includes {}'.format(profile, ','.join(includes)))
|
self.log.dbg('{} includes {}'.format(profile, ','.join(includes)))
|
||||||
self.log.dbg('{} dotfiles before include: {}'.format(profile,
|
self.log.dbg('{} dotfiles before include: {}'.format(profile,
|
||||||
@@ -549,6 +545,10 @@ class CfgYaml:
|
|||||||
|
|
||||||
seen = []
|
seen = []
|
||||||
for i in uniq_list(includes):
|
for i in uniq_list(includes):
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('resolving includes "{}" <- "{}"'
|
||||||
|
.format(profile, i))
|
||||||
|
|
||||||
# ensure no include loop occurs
|
# ensure no include loop occurs
|
||||||
if i in seen:
|
if i in seen:
|
||||||
raise YamlException('\"include loop\"')
|
raise YamlException('\"include loop\"')
|
||||||
@@ -559,35 +559,45 @@ class CfgYaml:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# recursive resolve
|
# recursive resolve
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('recursively resolving includes for profile "{}"'
|
||||||
|
.format(i))
|
||||||
o_dfs, o_actions, o_v, o_dv = self._rec_resolve_profile_include(i)
|
o_dfs, o_actions, o_v, o_dv = self._rec_resolve_profile_include(i)
|
||||||
|
|
||||||
# merge dotfile keys
|
# merge dotfile keys
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('Merging dotfiles {} <- {}: {} <- {}'
|
||||||
|
.format(profile, i, dotfiles, o_dfs))
|
||||||
dotfiles.extend(o_dfs)
|
dotfiles.extend(o_dfs)
|
||||||
this_profile[self.key_profile_dotfiles] = uniq_list(dotfiles)
|
this_profile[self.key_profile_dotfiles] = uniq_list(dotfiles)
|
||||||
|
|
||||||
# merge actions keys
|
# merge actions keys
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('Merging actions {} <- {}: {} <- {}'
|
||||||
|
.format(profile, i, actions, o_actions))
|
||||||
actions.extend(o_actions)
|
actions.extend(o_actions)
|
||||||
this_profile[self.key_profile_actions] = uniq_list(actions)
|
this_profile[self.key_profile_actions] = uniq_list(actions)
|
||||||
|
|
||||||
# merge variables
|
# merge variables
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('Merging variables {} <- {}: {} <- {}'
|
||||||
|
.format(profile, i, dict(pvars), dict(o_v)))
|
||||||
pvars = self._merge_dict(o_v, pvars)
|
pvars = self._merge_dict(o_v, pvars)
|
||||||
this_profile[self.key_profile_variables] = pvars
|
this_profile[self.key_profile_variables] = pvars
|
||||||
|
|
||||||
# merge dynvariables
|
# merge dynvariables
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('Merging dynamic variables {} <- {}: {} <- {}'
|
||||||
|
.format(profile, i, dict(pdvars),
|
||||||
|
dict(o_dv)))
|
||||||
pdvars = self._merge_dict(o_dv, pdvars)
|
pdvars = self._merge_dict(o_dv, pdvars)
|
||||||
self._shell_exec_dvars(pdvars.keys(), pdvars)
|
|
||||||
this_profile[self.key_profile_dvariables] = pdvars
|
this_profile[self.key_profile_dvariables] = pdvars
|
||||||
|
|
||||||
if i in included:
|
|
||||||
# only merge variables/dynvariables with the global variables
|
|
||||||
# if the considered profile is included by the selected profile
|
|
||||||
self.variables = self._merge_dict(pvars, self.variables)
|
|
||||||
self.variables = self._merge_dict(pdvars, self.variables)
|
|
||||||
|
|
||||||
dotfiles = this_profile.get(self.key_profile_dotfiles, [])
|
dotfiles = this_profile.get(self.key_profile_dotfiles, [])
|
||||||
actions = this_profile.get(self.key_profile_actions, [])
|
actions = this_profile.get(self.key_profile_actions, [])
|
||||||
pvars = this_profile.get(self.key_profile_variables, []) or []
|
pvars = this_profile.get(self.key_profile_variables, {}) or {}
|
||||||
pdvars = this_profile.get(self.key_profile_dvariables, []) or []
|
pdvars = this_profile.get(self.key_profile_dvariables, {}) or {}
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('{} dotfiles after include: {}'.format(profile,
|
self.log.dbg('{} dotfiles after include: {}'.format(profile,
|
||||||
dotfiles))
|
dotfiles))
|
||||||
@@ -598,6 +608,13 @@ class CfgYaml:
|
|||||||
self.log.dbg('{} dynvariables after include: {}'.format(profile,
|
self.log.dbg('{} dynvariables after include: {}'.format(profile,
|
||||||
pdvars))
|
pdvars))
|
||||||
|
|
||||||
|
if profile == self.profile:
|
||||||
|
# Only for the selected profile, we execute dynamic variables and
|
||||||
|
# we merge variables/dynvariables into the global variables
|
||||||
|
self._shell_exec_dvars(pdvars.keys(), pdvars)
|
||||||
|
self.variables = self._merge_dict(pvars, self.variables)
|
||||||
|
self.variables = self._merge_dict(pdvars, self.variables)
|
||||||
|
|
||||||
# since included items are resolved here
|
# since included items are resolved here
|
||||||
# we can clear these include
|
# we can clear these include
|
||||||
self.profiles[profile][self.key_profile_include] = None
|
self.profiles[profile][self.key_profile_include] = None
|
||||||
|
|||||||
@@ -117,14 +117,13 @@ echo "{{@@ maindyn @@}}" >> ${tmps}/dotfiles/abc
|
|||||||
echo "{{@@ subdyn @@}}" >> ${tmps}/dotfiles/abc
|
echo "{{@@ subdyn @@}}" >> ${tmps}/dotfiles/abc
|
||||||
echo "{{@@ subvar @@}}" >> ${tmps}/dotfiles/abc
|
echo "{{@@ subvar @@}}" >> ${tmps}/dotfiles/abc
|
||||||
echo "end" >> ${tmps}/dotfiles/abc
|
echo "end" >> ${tmps}/dotfiles/abc
|
||||||
cat ${tmps}/dotfiles/abc
|
#cat ${tmps}/dotfiles/abc
|
||||||
|
|
||||||
# install
|
# install
|
||||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p profile_1 --verbose
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p profile_1 --verbose
|
||||||
|
|
||||||
# check dotfile exists
|
# check dotfile exists
|
||||||
[ ! -e ${tmpd}/abc ] && exit 1
|
[ ! -e ${tmpd}/abc ] && exit 1
|
||||||
cat ${tmpd}/abc
|
|
||||||
grep 'maincontent' ${tmpd}/abc >/dev/null || (echo "variables 1 not resolved" && exit 1)
|
grep 'maincontent' ${tmpd}/abc >/dev/null || (echo "variables 1 not resolved" && exit 1)
|
||||||
grep 'maindyncontent' ${tmpd}/abc >/dev/null || (echo "dynvariables 1 not resolved" && exit 1)
|
grep 'maindyncontent' ${tmpd}/abc >/dev/null || (echo "dynvariables 1 not resolved" && exit 1)
|
||||||
grep 'subcontent' ${tmpd}/abc >/dev/null || (echo "variables 2 not resolved" && exit 1)
|
grep 'subcontent' ${tmpd}/abc >/dev/null || (echo "variables 2 not resolved" && exit 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user