mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 06:19:17 +00:00
add func_file and filter_file for the config (for #210)
This commit is contained in:
@@ -23,7 +23,7 @@ from dotdrop.exceptions import YamlException
|
|||||||
class CfgYaml:
|
class CfgYaml:
|
||||||
|
|
||||||
# global entries
|
# global entries
|
||||||
key_settings = 'config'
|
key_settings = Settings.key_yaml
|
||||||
key_dotfiles = 'dotfiles'
|
key_dotfiles = 'dotfiles'
|
||||||
key_profiles = 'profiles'
|
key_profiles = 'profiles'
|
||||||
key_actions = 'actions'
|
key_actions = 'actions'
|
||||||
@@ -61,12 +61,12 @@ class CfgYaml:
|
|||||||
key_import_ignore_key = 'optional'
|
key_import_ignore_key = 'optional'
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
key_settings_dotpath = 'dotpath'
|
key_settings_dotpath = Settings.key_dotpath
|
||||||
key_settings_workdir = 'workdir'
|
key_settings_workdir = Settings.key_workdir
|
||||||
key_settings_link_dotfile_default = 'link_dotfile_default'
|
key_settings_link_dotfile_default = Settings.key_link_dotfile_default
|
||||||
key_settings_noempty = 'ignoreempty'
|
key_settings_noempty = Settings.key_ignoreempty
|
||||||
key_settings_minversion = 'minversion'
|
key_settings_minversion = Settings.key_minversion
|
||||||
key_imp_link = 'link_on_import'
|
key_imp_link = Settings.key_link_on_import
|
||||||
|
|
||||||
# link values
|
# link values
|
||||||
lnk_nolink = LinkTypes.NOLINK.name.lower()
|
lnk_nolink = LinkTypes.NOLINK.name.lower()
|
||||||
@@ -216,7 +216,9 @@ class CfgYaml:
|
|||||||
|
|
||||||
def _resolve_dotfile_paths(self):
|
def _resolve_dotfile_paths(self):
|
||||||
"""resolve dotfile paths"""
|
"""resolve dotfile paths"""
|
||||||
t = Templategen(variables=self.variables)
|
t = Templategen(variables=self.variables,
|
||||||
|
func_file=self.settings[Settings.key_func_file],
|
||||||
|
filter_file=self.settings[Settings.key_filter_file])
|
||||||
|
|
||||||
for dotfile in self.dotfiles.values():
|
for dotfile in self.dotfiles.values():
|
||||||
# src
|
# src
|
||||||
@@ -248,7 +250,9 @@ class CfgYaml:
|
|||||||
def _rec_resolve_vars(self, variables):
|
def _rec_resolve_vars(self, variables):
|
||||||
"""recursive resolve variables"""
|
"""recursive resolve variables"""
|
||||||
default = self._get_variables_dict(self.profile)
|
default = self._get_variables_dict(self.profile)
|
||||||
t = Templategen(variables=self._merge_dict(default, variables))
|
t = Templategen(variables=self._merge_dict(default, variables),
|
||||||
|
func_file=self.settings[Settings.key_func_file],
|
||||||
|
filter_file=self.settings[Settings.key_filter_file])
|
||||||
for k in variables.keys():
|
for k in variables.keys():
|
||||||
val = variables[k]
|
val = variables[k]
|
||||||
while Templategen.var_is_template(val):
|
while Templategen.var_is_template(val):
|
||||||
@@ -284,7 +288,10 @@ class CfgYaml:
|
|||||||
self._debug_vars(merged)
|
self._debug_vars(merged)
|
||||||
|
|
||||||
# resolve profile includes
|
# resolve profile includes
|
||||||
t = Templategen(variables=merged)
|
t = Templategen(variables=merged,
|
||||||
|
func_file=self.settings[Settings.key_func_file],
|
||||||
|
filter_file=self.settings[Settings.key_filter_file])
|
||||||
|
|
||||||
for k, v in self.profiles.items():
|
for k, v in self.profiles.items():
|
||||||
if self.key_profile_include in v:
|
if self.key_profile_include in v:
|
||||||
new = []
|
new = []
|
||||||
@@ -314,7 +321,9 @@ class CfgYaml:
|
|||||||
|
|
||||||
def _apply_variables(self):
|
def _apply_variables(self):
|
||||||
"""template any needed parts of the config"""
|
"""template any needed parts of the config"""
|
||||||
t = Templategen(variables=self.variables)
|
t = Templategen(variables=self.variables,
|
||||||
|
func_file=self.settings[Settings.key_func_file],
|
||||||
|
filter_file=self.settings[Settings.key_filter_file])
|
||||||
|
|
||||||
# import_actions
|
# import_actions
|
||||||
new = []
|
new = []
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ profiles:
|
|||||||
p1:
|
p1:
|
||||||
dotfiles:
|
dotfiles:
|
||||||
- f_abc
|
- f_abc
|
||||||
|
variables:
|
||||||
|
filt: "{{@@ 'whatever' | filter1 @@}}"
|
||||||
_EOF
|
_EOF
|
||||||
#cat ${cfg}
|
#cat ${cfg}
|
||||||
|
|
||||||
@@ -116,6 +118,7 @@ echo "{{@@ "abc" | filter1 @@}}" >> ${tmps}/dotfiles/abc
|
|||||||
echo "{{@@ "arg1" | filter2('arg2') @@}}" >> ${tmps}/dotfiles/abc
|
echo "{{@@ "arg1" | filter2('arg2') @@}}" >> ${tmps}/dotfiles/abc
|
||||||
echo "{{@@ "13" | filter3() @@}}" >> ${tmps}/dotfiles/abc
|
echo "{{@@ "13" | filter3() @@}}" >> ${tmps}/dotfiles/abc
|
||||||
echo "{{@@ "something" | filter_ext() @@}}" >> ${tmps}/dotfiles/abc
|
echo "{{@@ "something" | filter_ext() @@}}" >> ${tmps}/dotfiles/abc
|
||||||
|
echo "{{@@ filt @@}}variable" >> ${tmps}/dotfiles/abc
|
||||||
|
|
||||||
# install
|
# install
|
||||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
@@ -129,6 +132,7 @@ grep '^external$' ${tmpd}/abc >/dev/null
|
|||||||
set +e
|
set +e
|
||||||
grep '^something$' ${tmpd}/abc >/dev/null && exit 1
|
grep '^something$' ${tmpd}/abc >/dev/null && exit 1
|
||||||
set -e
|
set -e
|
||||||
|
grep '^filteredvariable$' ${tmpd}/abc > /dev/null
|
||||||
|
|
||||||
## CLEANING
|
## CLEANING
|
||||||
rm -rf ${tmps} ${tmpd} ${filter_file} ${filter_file2} ${filter_file3}
|
rm -rf ${tmps} ${tmpd} ${filter_file} ${filter_file2} ${filter_file3}
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ profiles:
|
|||||||
p1:
|
p1:
|
||||||
dotfiles:
|
dotfiles:
|
||||||
- f_abc
|
- f_abc
|
||||||
|
variables:
|
||||||
|
func: "{{@@ func1(False) @@}}"
|
||||||
_EOF
|
_EOF
|
||||||
#cat ${cfg}
|
#cat ${cfg}
|
||||||
|
|
||||||
@@ -132,6 +134,8 @@ echo "{%@@ if func3("whatever") == 42 @@%}" >> ${tmps}/dotfiles/abc
|
|||||||
echo "externalok" >> ${tmps}/dotfiles/abc
|
echo "externalok" >> ${tmps}/dotfiles/abc
|
||||||
echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc
|
echo "{%@@ endif @@%}" >> ${tmps}/dotfiles/abc
|
||||||
|
|
||||||
|
echo "{{@@ func @@}}added" >> ${tmps}/dotfiles/abc
|
||||||
|
|
||||||
# install
|
# install
|
||||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
|
||||||
@@ -144,6 +148,7 @@ grep '^externalok$' ${tmpd}/abc >/dev/null
|
|||||||
set +e
|
set +e
|
||||||
grep '^nope$' ${tmpd}/abc >/dev/null && exit 1
|
grep '^nope$' ${tmpd}/abc >/dev/null && exit 1
|
||||||
set -e
|
set -e
|
||||||
|
grep '^Falseadded$' ${tmpd}/abc >/dev/null
|
||||||
|
|
||||||
## CLEANING
|
## CLEANING
|
||||||
rm -rf ${tmps} ${tmpd} ${func_file} ${func_file2} ${func_file3}
|
rm -rf ${tmps} ${tmpd} ${func_file} ${func_file2} ${func_file3}
|
||||||
|
|||||||
Reference in New Issue
Block a user