mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 13:54:17 +00:00
refactor the parsing
This commit is contained in:
@@ -93,6 +93,7 @@ create_conf ${cfg} # sets token
|
||||
echo "[+] import"
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/dir1
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} ${tmpd}/uniquefile
|
||||
cat ${cfg}
|
||||
|
||||
# let's see the dotpath
|
||||
#tree ${basedir}/dotfiles
|
||||
|
||||
@@ -79,9 +79,9 @@ echo "cfgpath: {{@@ _dotdrop_cfgpath @@}}" >> ${tmps}/dotfiles/abc
|
||||
echo "workdir: {{@@ _dotdrop_workdir @@}}" >> ${tmps}/dotfiles/abc
|
||||
|
||||
# install
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
#cat ${tmpd}/abc
|
||||
cat ${tmpd}/abc
|
||||
|
||||
grep "^dotpath: ${tmps}/dotfiles$" ${tmpd}/abc >/dev/null
|
||||
grep "^cfgpath: ${tmps}/config.yaml$" ${tmpd}/abc >/dev/null
|
||||
|
||||
@@ -81,7 +81,7 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
# checks
|
||||
[ ! -e ${tmpd}/abc ] && echo 'dotfile not installed' && exit 1
|
||||
#cat ${tmpd}/abc
|
||||
cat ${tmpd}/abc
|
||||
grep "src:${tmps}/dotfiles/abc" ${tmpd}/abc >/dev/null
|
||||
grep "dst:${tmpd}/abc" ${tmpd}/abc >/dev/null
|
||||
grep "key:f_abc" ${tmpd}/abc >/dev/null
|
||||
|
||||
@@ -96,7 +96,7 @@ _EOF
|
||||
echo "test" > ${tmps}/dotfiles/abc
|
||||
|
||||
# install
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
# checks
|
||||
[ ! -e ${tmpa}/pre ] && exit 1
|
||||
|
||||
130
tests-ng/import-configs.sh
Executable file
130
tests-ng/import-configs.sh
Executable file
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2019, deadc0de6
|
||||
#
|
||||
# import config testing
|
||||
#
|
||||
|
||||
# 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 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
|
||||
cfg1="${tmps}/config1.yaml"
|
||||
cfg2="${tmps}/config2.yaml"
|
||||
|
||||
cat > ${cfg1} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
import_configs:
|
||||
- ${cfg2}
|
||||
dotfiles:
|
||||
f_abc:
|
||||
dst: ${tmpd}/abc
|
||||
src: abc
|
||||
f_zzz:
|
||||
dst: ${tmpd}/zzz
|
||||
src: zzz
|
||||
f_sub:
|
||||
dst: ${tmpd}/sub
|
||||
src: sub
|
||||
profiles:
|
||||
p0:
|
||||
include:
|
||||
- p2
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
p3:
|
||||
dotfiles:
|
||||
- f_zzz
|
||||
pup:
|
||||
include:
|
||||
- psubsub
|
||||
_EOF
|
||||
|
||||
cat > ${cfg2} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dotfiles:
|
||||
f_def:
|
||||
dst: ${tmpd}/def
|
||||
src: def
|
||||
f_ghi:
|
||||
dst: ${tmpd}/ghi
|
||||
src: ghi
|
||||
profiles:
|
||||
p2:
|
||||
dotfiles:
|
||||
- f_def
|
||||
psubsub:
|
||||
dotfiles:
|
||||
- f_sub
|
||||
_EOF
|
||||
|
||||
# create the source
|
||||
mkdir -p ${tmps}/dotfiles/
|
||||
echo "abc" > ${tmps}/dotfiles/abc
|
||||
echo "def" > ${tmps}/dotfiles/def
|
||||
echo "ghi" > ${tmps}/dotfiles/ghi
|
||||
echo "zzz" > ${tmps}/dotfiles/zzz
|
||||
echo "sub" > ${tmps}/dotfiles/sub
|
||||
|
||||
# install
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p p0 -V | grep f_def
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p p1 -V | grep f_abc
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p p2 -V | grep f_def
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p p3 -V | grep f_zzz
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p pup -V | grep f_sub
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg1} -p psubsub -V | grep f_sub
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
127
tests-ng/import-profile-dotfiles.sh
Executable file
127
tests-ng/import-profile-dotfiles.sh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2017, deadc0de6
|
||||
#
|
||||
# test the use of the keyword "import" in profiles
|
||||
# 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 dotfile source
|
||||
tmps=`mktemp -d --suffix='-dotdrop-tests'`
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
# the dotfile destination
|
||||
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
|
||||
extdotfiles="${tmps}/df_p1.yaml"
|
||||
|
||||
dynextdotfiles_name="d_uid_dynvar"
|
||||
dynextdotfiles="${tmps}/ext_${dynextdotfiles_name}"
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dynvariables:
|
||||
d_uid: "echo ${dynextdotfiles_name}"
|
||||
dotfiles:
|
||||
f_abc:
|
||||
dst: ${tmpd}/abc
|
||||
src: abc
|
||||
f_def:
|
||||
dst: ${tmpd}/def
|
||||
src: def
|
||||
f_xyz:
|
||||
dst: ${tmpd}/xyz
|
||||
src: xyz
|
||||
f_dyn:
|
||||
dst: ${tmpd}/dyn
|
||||
src: dyn
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
import:
|
||||
- $(basename ${extdotfiles})
|
||||
- "ext_{{@@ d_uid @@}}"
|
||||
_EOF
|
||||
|
||||
# create the external dotfile file
|
||||
cat > ${extdotfiles} << _EOF
|
||||
dotfiles:
|
||||
- f_def
|
||||
- f_xyz
|
||||
_EOF
|
||||
|
||||
cat > ${dynextdotfiles} << _EOF
|
||||
dotfiles:
|
||||
- f_dyn
|
||||
_EOF
|
||||
|
||||
# create the source
|
||||
mkdir -p ${tmps}/dotfiles/
|
||||
echo "abc" > ${tmps}/dotfiles/abc
|
||||
echo "def" > ${tmps}/dotfiles/def
|
||||
echo "xyz" > ${tmps}/dotfiles/xyz
|
||||
echo "dyn" > ${tmps}/dotfiles/dyn
|
||||
|
||||
# install
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
# checks
|
||||
[ ! -e ${tmpd}/abc ] && exit 1
|
||||
[ ! -e ${tmpd}/def ] && exit 1
|
||||
[ ! -e ${tmpd}/xyz ] && exit 1
|
||||
[ ! -e ${tmpd}/dyn ] && exit 1
|
||||
echo 'file found'
|
||||
grep 'abc' ${tmpd}/abc >/dev/null 2>&1
|
||||
grep 'def' ${tmpd}/def >/dev/null 2>&1
|
||||
grep 'xyz' ${tmpd}/xyz >/dev/null 2>&1
|
||||
grep 'dyn' ${tmpd}/dyn >/dev/null 2>&1
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2017, deadc0de6
|
||||
# Copyright (c) 2019, deadc0de6
|
||||
#
|
||||
# test the use of the keyword "import" in profiles
|
||||
# returns 1 in case of error
|
||||
# test basic import
|
||||
#
|
||||
|
||||
# exit on first error
|
||||
@@ -50,10 +49,13 @@ tmps=`mktemp -d --suffix='-dotdrop-tests'`
|
||||
mkdir -p ${tmps}/dotfiles
|
||||
# the dotfile destination
|
||||
tmpd=`mktemp -d --suffix='-dotdrop-tests'`
|
||||
extdotfiles="${tmps}/df_p1.yaml"
|
||||
#echo "dotfile destination: ${tmpd}"
|
||||
|
||||
dynextdotfiles_name="d_uid_dynvar"
|
||||
dynextdotfiles="${tmps}/ext_${dynextdotfiles_name}"
|
||||
# create the dotfile
|
||||
mkdir -p ${tmpd}/adir
|
||||
echo "adir/file1" > ${tmpd}/adir/file1
|
||||
echo "adir/fil2" > ${tmpd}/adir/file2
|
||||
echo "file3" > ${tmpd}/file3
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
@@ -63,61 +65,30 @@ config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dynvariables:
|
||||
d_uid: "echo ${dynextdotfiles_name}"
|
||||
dotfiles:
|
||||
f_abc:
|
||||
dst: ${tmpd}/abc
|
||||
src: abc
|
||||
f_def:
|
||||
dst: ${tmpd}/def
|
||||
src: def
|
||||
f_xyz:
|
||||
dst: ${tmpd}/xyz
|
||||
src: xyz
|
||||
f_dyn:
|
||||
dst: ${tmpd}/dyn
|
||||
src: dyn
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
import:
|
||||
- $(basename ${extdotfiles})
|
||||
- "ext_{{@@ d_uid @@}}"
|
||||
_EOF
|
||||
#cat ${cfg}
|
||||
|
||||
# create the external dotfile file
|
||||
cat > ${extdotfiles} << _EOF
|
||||
dotfiles:
|
||||
- f_def
|
||||
- f_xyz
|
||||
_EOF
|
||||
# import
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir
|
||||
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/file3
|
||||
|
||||
cat > ${dynextdotfiles} << _EOF
|
||||
dotfiles:
|
||||
- f_dyn
|
||||
_EOF
|
||||
cat ${cfg}
|
||||
|
||||
# create the source
|
||||
mkdir -p ${tmps}/dotfiles/
|
||||
echo "abc" > ${tmps}/dotfiles/abc
|
||||
echo "def" > ${tmps}/dotfiles/def
|
||||
echo "xyz" > ${tmps}/dotfiles/xyz
|
||||
echo "dyn" > ${tmps}/dotfiles/dyn
|
||||
# ensure exists and is not link
|
||||
[ ! -d ${tmps}/dotfiles/${tmpd}/adir ] && echo "not a directory" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file2 ] && echo "not exist" && exit 1
|
||||
[ ! -e ${tmps}/dotfiles/${tmpd}/file3 ] && echo "not a file" && exit 1
|
||||
|
||||
# install
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
cat ${cfg} | grep ${tmpd}/adir >/dev/null 2>&1
|
||||
cat ${cfg} | grep ${tmpd}/file3 >/dev/null 2>&1
|
||||
|
||||
# checks
|
||||
[ ! -e ${tmpd}/abc ] && exit 1
|
||||
[ ! -e ${tmpd}/def ] && exit 1
|
||||
[ ! -e ${tmpd}/xyz ] && exit 1
|
||||
[ ! -e ${tmpd}/dyn ] && exit 1
|
||||
grep 'abc' ${tmpd}/abc >/dev/null 2>&1
|
||||
grep 'def' ${tmpd}/def >/dev/null 2>&1
|
||||
grep 'xyz' ${tmpd}/xyz >/dev/null 2>&1
|
||||
grep 'dyn' ${tmpd}/dyn >/dev/null 2>&1
|
||||
nb=`cat ${cfg} | grep d_adir | wc -l`
|
||||
[ "${nb}" != "2" ] && echo 'bad config1' && exit 1
|
||||
nb=`cat ${cfg} | grep f_file3 | wc -l`
|
||||
[ "${nb}" != "2" ] && echo 'bad config2' && exit 1
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
@@ -64,12 +64,18 @@ dotfiles:
|
||||
dst: ${tmpd}/abc
|
||||
src: abc
|
||||
profiles:
|
||||
p0:
|
||||
include:
|
||||
- p3
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
p2:
|
||||
include:
|
||||
- p1
|
||||
p3:
|
||||
include:
|
||||
- p2
|
||||
_EOF
|
||||
|
||||
# create the source
|
||||
@@ -82,6 +88,14 @@ cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1
|
||||
# compare
|
||||
cd ${ddpath} | ${bin} compare -c ${cfg} -p p1
|
||||
cd ${ddpath} | ${bin} compare -c ${cfg} -p p2
|
||||
cd ${ddpath} | ${bin} compare -c ${cfg} -p p3
|
||||
cd ${ddpath} | ${bin} compare -c ${cfg} -p p0
|
||||
|
||||
# list
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 | grep f_abc
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p2 | grep f_abc
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p3 | grep f_abc
|
||||
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p0 | grep f_abc
|
||||
|
||||
# count
|
||||
cnt=`cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -b | grep '^f_' | wc -l`
|
||||
|
||||
Reference in New Issue
Block a user