diff --git a/dotdrop/cfg_yaml.py b/dotdrop/cfg_yaml.py index 0fa855b..bfe959b 100644 --- a/dotdrop/cfg_yaml.py +++ b/dotdrop/cfg_yaml.py @@ -244,6 +244,21 @@ class CfgYaml: self.log.dbg('resolved: {}'.format(new)) v[self.key_dotfile_actions] = new + # profile entries + try: + this_profile = self.profiles[self.profile] + # actions + this_profile[self.key_profile_actions] = [ + t.generate_string(a) + for a in this_profile.get(self.key_profile_actions, []) + ] + this_profile_actions = this_profile[self.key_profile_actions] + if this_profile_actions and self.debug: + self.log.dbg('resolved: {}'.format(this_profile_actions)) + except KeyError: + # self.profile is not in the YAML file + pass + # external actions paths new = [] for p in self.settings.get(self.key_import_actions, []): diff --git a/tests-ng/actions-args-template.sh b/tests-ng/actions-args-template.sh new file mode 100755 index 0000000..944f1f8 --- /dev/null +++ b/tests-ng/actions-args-template.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2017, deadc0de6 +# +# test action template execution +# returns 1 in case of error +# + +# exit on first error +set -e + +# all this crap to get current path +rl="readlink -f" +if ! ${rl} "${0}" >/dev/null 2>&1; then + rl="realpath" + + if ! hash ${rl}; then + echo "\"${rl}\" not found !" && exit 1 + fi +fi +cur=$(dirname "$(${rl} "${0}")") + +#hash dotdrop >/dev/null 2>&1 +#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1 + +#echo "called with ${1}" + +# dotdrop path can be pass as argument +ddpath="${cur}/../" +[ "${1}" != "" ] && ddpath="${1}" +[ ! -d ${ddpath} ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1 + +export PYTHONPATH="${ddpath}:${PYTHONPATH}" +bin="python3 -m dotdrop.dotdrop" + +echo "dotdrop path: ${ddpath}" +echo "pythonpath: ${PYTHONPATH}" + +# get the helpers +source ${cur}/helpers + +echo -e "\e[96m\e[1m==> RUNNING $(basename $BASH_SOURCE) <==\e[0m" + +################################################################ +# this is the test +################################################################ + +# the action temp +tmpa=`mktemp -d --suffix='-dotdrop-tests'` +# the dotfile source +tmps=`mktemp -d --suffix='-dotdrop-tests'` +mkdir -p ${tmps}/dotfiles +# the dotfile destination +tmpd=`mktemp -d --suffix='-dotdrop-tests'` + +# create the config file +cfg="${tmps}/config.yaml" + +cat > ${cfg} << _EOF +actions: + pre: + preaction: "echo {0} > {1}" + post: + postaction: "echo {0} > ${tmpa}/post" + nakedaction: "echo {0} > ${tmpa}/naked" + profileaction: "echo {0} > ${tmpa}/profile" + dynaction: "echo {0} > ${tmpa}/dyn" +config: + backup: true + create: true + dotpath: dotfiles + default_actions: + - preaction '{{@@ var_pre @@}}' "${tmpa}/pre" + - postaction '{{@@ var_post @@}}' + - nakedaction '{{@@ var_naked @@}}' +dotfiles: + f_abc: + dst: ${tmpd}/abc + src: abc +profiles: + p1: + dotfiles: + - f_abc + actions: + - profileaction '{{@@ var_profile @@}}' + - dynaction '{{@@ user_name @@}}' +variables: + var_pre: var_pre + var_post: var_post + var_naked: var_naked + var_profile: var_profile +dynvariables: + user_name: 'echo $USER' +_EOF +#cat ${cfg} + +# create the dotfile +echo 'test' > ${tmps}/dotfiles/abc + +# install +cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V + +# checks action +[ ! -e ${tmpa}/pre ] && echo 'pre action not executed' && exit 1 +[ ! -e ${tmpa}/post ] && echo 'post action not executed' && exit 1 +[ ! -e ${tmpa}/naked ] && echo 'naked action not executed' && exit 1 +[ ! -e ${tmpa}/profile ] && echo 'profile action not executed' && exit 1 +[ ! -e ${tmpa}/dyn ] && echo 'dynamic acton action not executed' && exit 1 +grep var_pre ${tmpa}/pre >/dev/null +grep var_post ${tmpa}/post >/dev/null +grep var_naked ${tmpa}/naked >/dev/null +grep var_profile ${tmpa}/profile >/dev/null +grep "$USER" ${tmpa}/dyn >/dev/null + +## CLEANING +rm -rf ${tmps} ${tmpd} ${tmpa} + +echo "OK" +exit 0