1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 18:34:48 +00:00

improve pre/post actions and add test

This commit is contained in:
deadc0de6
2018-06-02 15:55:24 +02:00
parent 2af2a6132a
commit bd17f1eb45
2 changed files with 109 additions and 5 deletions

View File

@@ -123,6 +123,7 @@ class Cfg:
if self.key_actions in self.content:
if self.content[self.key_actions] is not None:
for k, v in self.content[self.key_actions].items():
# loop through all actions
if k in [self.key_actions_pre, self.key_actions_post]:
# parse pre/post actions
items = self.content[self.key_actions][k].items()
@@ -132,7 +133,9 @@ class Cfg:
self.actions[k][k2] = Action(k2, v2)
else:
# parse naked actions as post actions
self.actions[k] = Action(k, v)
if self.key_actions_post not in self.actions:
self.actions[self.key_actions_post] = {}
self.actions[self.key_actions_post][k] = Action(k, v)
# parse all transformations
if self.key_trans in self.content:
@@ -246,12 +249,9 @@ class Cfg:
entry in self.actions[self.key_actions_post]:
key = self.key_actions_post
action = self.actions[self.key_actions_post][entry]
elif entry not in self.actions.keys():
else:
self.log.warn('unknown action \"{}\"'.format(entry))
continue
else:
key = self.key_actions_post
action = self.actions[entry]
res[key].append(action)
return res

104
tests-ng/actions.sh Executable file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6
#
# test pre/post/naked actions
# 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 "RUNNING $(basename $BASH_SOURCE)"
################################################################
# this is the test
################################################################
# the action temp
tmpa=`mktemp -d`
# the dotfile source
tmps=`mktemp -d`
mkdir -p ${tmps}/dotfiles
# the dotfile destination
tmpd=`mktemp -d`
# create the config file
cfg="${tmps}/config.yaml"
cat > ${cfg} << _EOF
actions:
pre:
preaction: echo 'pre' > ${tmpa}/pre
post:
postaction: echo 'post' > ${tmpa}/post
nakedaction: echo 'naked' > ${tmpa}/naked
config:
backup: true
create: true
dotpath: dotfiles
dotfiles:
f_abc:
dst: ${tmpd}/abc
src: abc
actions:
- preaction
- postaction
- nakedaction
profiles:
p1:
dotfiles:
- f_abc
_EOF
cat ${cfg}
# create the dotfile
echo "test" > ${tmps}/dotfiles/abc
tree ${tmps}
# install
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
# checks
[ ! -e ${tmpa}/pre ] && exit 1
grep pre ${tmpa}/pre >/dev/null
[ ! -e ${tmpa}/post ] && exit 1
grep post ${tmpa}/post >/dev/null
[ ! -e ${tmpa}/naked ] && exit 1
grep naked ${tmpa}/naked >/dev/null
## CLEANING
rm -rf ${tmps} ${tmpd} ${tmpa}
echo "OK"
exit 0