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/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 } 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} 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 diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 6253d3f..193c276 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -353,7 +353,23 @@ 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 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)) + if overwrite: cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))] if o.dry: LOG.dry('would run: {}'.format(' '.join(cmd))) 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 ...] diff --git a/tests-ng/import-subfile.sh b/tests-ng/import-subfile.sh new file mode 100755 index 0000000..c0746d1 --- /dev/null +++ b/tests-ng/import-subfile.sh @@ -0,0 +1,90 @@ +#!/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 -f -c ${cfg} -p p1 -V ${tmpd}/adir + +# change the file +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 >/dev/null + +## CLEANING +rm -rf ${tmps} ${tmpd} + +echo "OK" +exit 0 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