From 6074ec07b3182eac20205b2fbbe1c6e0b9ff3d2b Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 06:24:36 -0400 Subject: [PATCH 1/7] handle reimport of file within imported directory --- dotdrop/dotdrop.py | 16 ++++++- tests-ng/import-subfile.sh | 89 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100755 tests-ng/import-subfile.sh diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 6253d3f..8846694 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -353,7 +353,21 @@ def cmd_importer(o): # prepare hierarchy for dotfile srcf = os.path.join(o.dotpath, src) - if not os.path.exists(srcf): + overwrite = not os.path.exists(srcf) + if o.safe and os.path.exists(srcf): + c = Comparator(debug=o.debug) + diff = c.compare(srcf, dst) + if diff != '': + # files are different, dunno what to do + LOG.log('diff \"{}\" VS \"{}\"'.format(dst, srcf)) + LOG.emph(diff) + # ask user + msg = 'Dotfile \"{}\" already exists, overwrite?'.format(srcf) + overwrite = LOG.ask(msg) + + if o.debug: + LOG.dbg('will overwrite: {}'.format(overwrite)) + if overwrite: cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))] if o.dry: LOG.dry('would run: {}'.format(' '.join(cmd))) diff --git a/tests-ng/import-subfile.sh b/tests-ng/import-subfile.sh new file mode 100755 index 0000000..5b466e8 --- /dev/null +++ b/tests-ng/import-subfile.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2019, deadc0de6 +# +# test import file in directory +# after having imported directory +# + +# 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'` +#echo "dotfile destination: ${tmpd}" + +# create the dotfile +mkdir -p ${tmpd}/adir +echo "first" > ${tmpd}/adir/file1 + +# create the config file +cfg="${tmps}/config.yaml" + +cat > ${cfg} << _EOF +config: + backup: true + create: true + dotpath: dotfiles +dotfiles: +profiles: +_EOF +#cat ${cfg} + +# import dir +cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir + +# change the file +echo "second" > ${tmpd}/adir/file1 + +# import file +cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir/file1 + +# test +[ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 +grep 'second' ${tmps}/dotfiles/${tmpd}/adir/file1 + +## CLEANING +rm -rf ${tmps} ${tmpd} + +echo "OK" +exit 0 From 20d1bd11293af90a80685c60d27822ae68c91a17 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 08:54:25 -0400 Subject: [PATCH 2/7] typo --- dotdrop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotdrop.sh b/dotdrop.sh index 4559faa..a469f7f 100755 --- a/dotdrop.sh +++ b/dotdrop.sh @@ -10,7 +10,7 @@ if ! ${rl} "${0}" >/dev/null 2>&1; then rl="realpath" if ! hash ${rl}; then - echo "\"${rl}\" not found !" && exit 1 + echo "\"${rl}\" not found!" && exit 1 fi fi From ecaed77a65712a1fe4910ddb469692d4d31f4b44 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 09:17:41 -0400 Subject: [PATCH 3/7] adding script to generate completion --- completion/generate.sh | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 completion/generate.sh diff --git a/completion/generate.sh b/completion/generate.sh new file mode 100755 index 0000000..c25cb91 --- /dev/null +++ b/completion/generate.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# author: deadc0de6 (https://github.com/deadc0de6) +# Copyright (c) 2019, deadc0de6 + +set -e + +bin="docopt-completion" +if ! hash ${bin}; then + echo "\"${bin}\" not found!" + exit 1 +fi + +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}")") +opwd=$(pwd) + +# output files +compl="${cur}" +dtsh_zsh="${compl}/_dotdrop.sh-completion.zsh" +dtsh_bash="${compl}/dotdrop.sh-completion.bash" +dt_zsh="${compl}/_dotdrop-completion.zsh" +dt_bash="${compl}/dotdrop-completion.bash" + +# generate for dotdrop.sh +cd ${cur}/.. +docopt-completion ./dotdrop.sh --manual-zsh +mv ./_dotdrop.sh ${dtsh_zsh} +docopt-completion ./dotdrop.sh --manual-bash +mv ./dotdrop.sh.sh ${dtsh_bash} + +# generate for dotdrop +vbin="virtualenv" +if ! hash ${vbin}; then + echo "\"${vbin}\" not found!" + exit 1 +fi +cd ${cur}/.. +venv="/tmp/dotdrop-venv" +${vbin} -p python3 ${venv} +source ${venv}/bin/activate +python setup.py install +cd /tmp +docopt-completion dotdrop --manual-zsh +mv ./_dotdrop ${dt_zsh} +docopt-completion dotdrop --manual-bash +mv ./dotdrop.sh ${dt_bash} +deactivate +rm -rf ${venv} + +# pivot back +cd ${opwd} From 0de244af31b620030d9fd0d428e523b65ba02812 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 09:21:15 -0400 Subject: [PATCH 4/7] adding -f --force to import --- dotdrop/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotdrop/options.py b/dotdrop/options.py index 291384e..4933076 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -52,7 +52,7 @@ USAGE = """ Usage: dotdrop install [-VbtfndDa] [-c ] [-p ] [...] - dotdrop import [-Vbd] [-c ] [-p ] + dotdrop import [-Vbdf] [-c ] [-p ] [-l ] ... dotdrop compare [-Vb] [-c ] [-p ] [-o ] [-C ...] [-i ...] From aaf099d650e110c68cc3ac1ab949b2636f153922 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 09:52:52 -0400 Subject: [PATCH 5/7] update completion files --- completion/_dotdrop-completion.zsh | 2 ++ completion/_dotdrop.sh-completion.zsh | 2 ++ completion/dotdrop-completion.bash | 2 +- completion/dotdrop.sh-completion.bash | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/completion/_dotdrop-completion.zsh b/completion/_dotdrop-completion.zsh index 7062241..b2480a7 100644 --- a/completion/_dotdrop-completion.zsh +++ b/completion/_dotdrop-completion.zsh @@ -127,6 +127,8 @@ _dotdrop-import () '(--no-banner)--no-banner' \ '(-d)-d' \ '(--dry)--dry' \ + '(-f)-f' \ + '(--force)--force' \ '(-c=-)-c=-' \ '(--cfg=-)--cfg=-' \ '(-p=-)-p=-' \ diff --git a/completion/_dotdrop.sh-completion.zsh b/completion/_dotdrop.sh-completion.zsh index a123621..10e2fb0 100644 --- a/completion/_dotdrop.sh-completion.zsh +++ b/completion/_dotdrop.sh-completion.zsh @@ -127,6 +127,8 @@ _dotdrop.sh-import () '(--no-banner)--no-banner' \ '(-d)-d' \ '(--dry)--dry' \ + '(-f)-f' \ + '(--force)--force' \ '(-c=-)-c=-' \ '(--cfg=-)--cfg=-' \ '(-p=-)-p=-' \ diff --git a/completion/dotdrop-completion.bash b/completion/dotdrop-completion.bash index 92f2ffb..a1c3691 100644 --- a/completion/dotdrop-completion.bash +++ b/completion/dotdrop-completion.bash @@ -53,7 +53,7 @@ _dotdrop_import() cur="${COMP_WORDS[COMP_CWORD]}" if [ $COMP_CWORD -ge 2 ]; then - COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -d --dry -c= --cfg= -p= --profile= -l= --link= ' -- $cur) ) + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -d --dry -f --force -c= --cfg= -p= --profile= -l= --link= ' -- $cur) ) fi } diff --git a/completion/dotdrop.sh-completion.bash b/completion/dotdrop.sh-completion.bash index c6e0760..bb76f95 100644 --- a/completion/dotdrop.sh-completion.bash +++ b/completion/dotdrop.sh-completion.bash @@ -53,7 +53,7 @@ _dotdropsh_import() cur="${COMP_WORDS[COMP_CWORD]}" if [ $COMP_CWORD -ge 2 ]; then - COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -d --dry -c= --cfg= -p= --profile= -l= --link= ' -- $cur) ) + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -d --dry -f --force -c= --cfg= -p= --profile= -l= --link= ' -- $cur) ) fi } From a13a96b68ba74f185a20a2c030233e336d8e940a Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 09:56:55 -0400 Subject: [PATCH 6/7] fix import for tests --- tests-ng/import-subfile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests-ng/import-subfile.sh b/tests-ng/import-subfile.sh index 5b466e8..0dc27d1 100755 --- a/tests-ng/import-subfile.sh +++ b/tests-ng/import-subfile.sh @@ -70,13 +70,13 @@ _EOF #cat ${cfg} # import dir -cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir +cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir # change the file echo "second" > ${tmpd}/adir/file1 # import file -cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V ${tmpd}/adir/file1 +cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir/file1 # test [ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 From 01597c9c242f30bcc4b2cc5808442de9f8e4bdfa Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 24 Jun 2019 22:28:09 -0400 Subject: [PATCH 7/7] fix import and debug for travis --- .travis.yml | 4 ++++ dotdrop/dotdrop.py | 22 ++++++++++++---------- tests-ng/import-subfile.sh | 5 +++-- tests.sh | 4 ---- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index e60a940..cba0f41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,3 +12,7 @@ script: ./tests.sh after_success: coveralls +env: + global: + - DOTDROP_FORCE_NODEBUG= + - DOTDROP_NOBANNER= diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 8846694..193c276 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -354,16 +354,18 @@ def cmd_importer(o): # prepare hierarchy for dotfile srcf = os.path.join(o.dotpath, src) overwrite = not os.path.exists(srcf) - if o.safe and os.path.exists(srcf): - c = Comparator(debug=o.debug) - diff = c.compare(srcf, dst) - if diff != '': - # files are different, dunno what to do - LOG.log('diff \"{}\" VS \"{}\"'.format(dst, srcf)) - LOG.emph(diff) - # ask user - msg = 'Dotfile \"{}\" already exists, overwrite?'.format(srcf) - overwrite = LOG.ask(msg) + if os.path.exists(srcf): + overwrite = True + if o.safe: + c = Comparator(debug=o.debug) + diff = c.compare(srcf, dst) + if diff != '': + # files are different, dunno what to do + LOG.log('diff \"{}\" VS \"{}\"'.format(dst, srcf)) + LOG.emph(diff) + # ask user + msg = 'Dotfile \"{}\" already exists, overwrite?' + overwrite = LOG.ask(msg.format(srcf)) if o.debug: LOG.dbg('will overwrite: {}'.format(overwrite)) diff --git a/tests-ng/import-subfile.sh b/tests-ng/import-subfile.sh index 0dc27d1..c0746d1 100755 --- a/tests-ng/import-subfile.sh +++ b/tests-ng/import-subfile.sh @@ -73,14 +73,15 @@ _EOF cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir # change the file -echo "second" > ${tmpd}/adir/file1 +echo "second" >> ${tmpd}/adir/file1 # import file cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 -V ${tmpd}/adir/file1 # test +#cat ${tmps}/dotfiles/${tmpd}/adir/file1 [ ! -e ${tmps}/dotfiles/${tmpd}/adir/file1 ] && echo "not exist" && exit 1 -grep 'second' ${tmps}/dotfiles/${tmpd}/adir/file1 +grep 'second' ${tmps}/dotfiles/${tmpd}/adir/file1 >/dev/null ## CLEANING rm -rf ${tmps} ${tmpd} diff --git a/tests.sh b/tests.sh index 3a33715..3974bb3 100755 --- a/tests.sh +++ b/tests.sh @@ -25,10 +25,6 @@ which ${nosebin} 2>/dev/null [ "$?" != "0" ] && echo "Install nosetests" && exit 1 set -e -# comment this to get debug info -#export DOTDROP_FORCE_NODEBUG= -#export DOTDROP_NOBANNER= - # execute tests with coverage PYTHONPATH=dotdrop ${nosebin} -s --with-coverage --cover-package=dotdrop #PYTHONPATH=dotdrop python3 -m pytest tests