mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 00:19:15 +00:00
refactor links and add more tests
This commit is contained in:
@@ -70,9 +70,9 @@ class Cfg:
|
|||||||
key_profiles_imp = 'import'
|
key_profiles_imp = 'import'
|
||||||
|
|
||||||
# link values
|
# link values
|
||||||
lnk_parent = 'link'
|
lnk_nolink = LinkTypes.NOLINK.name.lower()
|
||||||
lnk_nolink = 'nolink'
|
lnk_link = LinkTypes.LINK.name.lower()
|
||||||
lnk_children = 'link_children'
|
lnk_children = LinkTypes.LINK_CHILDREN.name.lower()
|
||||||
|
|
||||||
# settings defaults
|
# settings defaults
|
||||||
default_dotpath = 'dotfiles'
|
default_dotpath = 'dotfiles'
|
||||||
@@ -198,22 +198,12 @@ class Cfg:
|
|||||||
|
|
||||||
def _string_to_linktype(self, string):
|
def _string_to_linktype(self, string):
|
||||||
"""translate string to linktype"""
|
"""translate string to linktype"""
|
||||||
if string == self.lnk_parent.lower():
|
if string == self.lnk_link.lower():
|
||||||
return LinkTypes.PARENT
|
return LinkTypes.LINK
|
||||||
elif string == self.lnk_children.lower():
|
elif string == self.lnk_children.lower():
|
||||||
return LinkTypes.CHILDREN
|
return LinkTypes.LINK_CHILDREN
|
||||||
return LinkTypes.NOLINK
|
return LinkTypes.NOLINK
|
||||||
|
|
||||||
def _linktype_to_string(self, link):
|
|
||||||
"""translate linktype to string"""
|
|
||||||
if link == LinkTypes.PARENT:
|
|
||||||
return self.lnk_parent
|
|
||||||
elif link == LinkTypes.CHILDREN:
|
|
||||||
return self.lnk_children
|
|
||||||
elif link == LinkTypes.NOLINK:
|
|
||||||
return self.lnk_nolink
|
|
||||||
return self.lnk_nolink
|
|
||||||
|
|
||||||
def _parse(self, profile=None):
|
def _parse(self, profile=None):
|
||||||
"""parse config file"""
|
"""parse config file"""
|
||||||
# parse the settings
|
# parse the settings
|
||||||
@@ -602,7 +592,7 @@ class Cfg:
|
|||||||
self.lnk_settings[self.key_dotfile_link] = self.default_link
|
self.lnk_settings[self.key_dotfile_link] = self.default_link
|
||||||
else:
|
else:
|
||||||
key = self.lnk_settings[self.key_dotfile_link]
|
key = self.lnk_settings[self.key_dotfile_link]
|
||||||
if key != self.lnk_parent and \
|
if key != self.lnk_link and \
|
||||||
key != self.lnk_children and \
|
key != self.lnk_children and \
|
||||||
key != self.lnk_nolink:
|
key != self.lnk_nolink:
|
||||||
self.log.err('bad value for {}'.format(self.key_dotfile_link))
|
self.log.err('bad value for {}'.format(self.key_dotfile_link))
|
||||||
@@ -612,7 +602,7 @@ class Cfg:
|
|||||||
self.lnk_settings[self.key_imp_link] = self.default_link_imp
|
self.lnk_settings[self.key_imp_link] = self.default_link_imp
|
||||||
else:
|
else:
|
||||||
key = self.lnk_settings[self.key_imp_link]
|
key = self.lnk_settings[self.key_imp_link]
|
||||||
if key != self.lnk_parent and \
|
if key != self.lnk_link and \
|
||||||
key != self.lnk_children and \
|
key != self.lnk_children and \
|
||||||
key != self.lnk_nolink:
|
key != self.lnk_nolink:
|
||||||
self.log.err('bad value for {}'.format(self.key_dotfile_link))
|
self.log.err('bad value for {}'.format(self.key_dotfile_link))
|
||||||
@@ -626,7 +616,7 @@ class Cfg:
|
|||||||
newkey = self.key_imp_link
|
newkey = self.key_imp_link
|
||||||
if key in self.lnk_settings:
|
if key in self.lnk_settings:
|
||||||
if self.lnk_settings[key]:
|
if self.lnk_settings[key]:
|
||||||
self.lnk_settings[newkey] = self.lnk_parent
|
self.lnk_settings[newkey] = self.lnk_link
|
||||||
else:
|
else:
|
||||||
self.lnk_settings[newkey] = self.lnk_nolink
|
self.lnk_settings[newkey] = self.lnk_nolink
|
||||||
del self.lnk_settings[key]
|
del self.lnk_settings[key]
|
||||||
@@ -646,7 +636,7 @@ class Cfg:
|
|||||||
and type(v[self.key_dotfiles_link]) is bool:
|
and type(v[self.key_dotfiles_link]) is bool:
|
||||||
# patch link: <bool>
|
# patch link: <bool>
|
||||||
if v[self.key_dotfiles_link]:
|
if v[self.key_dotfiles_link]:
|
||||||
new = self.lnk_parent
|
new = self.lnk_link
|
||||||
else:
|
else:
|
||||||
new = self.lnk_nolink
|
new = self.lnk_nolink
|
||||||
self._modified = True
|
self._modified = True
|
||||||
@@ -755,12 +745,12 @@ class Cfg:
|
|||||||
return False, self._get_long_key(path, keys)
|
return False, self._get_long_key(path, keys)
|
||||||
return False, self._get_short_key(path, keys)
|
return False, self._get_short_key(path, keys)
|
||||||
|
|
||||||
def new(self, dotfile, profile, link=LinkTypes.NOLINK, debug=False):
|
def new(self, src, dst, profile, link, debug=False):
|
||||||
"""import new dotfile
|
"""import new dotfile"""
|
||||||
dotfile key will change and can be empty"""
|
|
||||||
# keep it short
|
# keep it short
|
||||||
home = os.path.expanduser('~')
|
home = os.path.expanduser('~')
|
||||||
dotfile.dst = dotfile.dst.replace(home, '~', 1)
|
dst = dst.replace(home, '~', 1)
|
||||||
|
dotfile = Dotfile('', dst, src)
|
||||||
|
|
||||||
# adding new profile if doesn't exist
|
# adding new profile if doesn't exist
|
||||||
if profile not in self.lnk_profiles:
|
if profile not in self.lnk_profiles:
|
||||||
@@ -806,8 +796,8 @@ class Cfg:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# set the link flag
|
# set the link flag
|
||||||
if link != LinkTypes.NOLINK:
|
if link != self._get_def_link():
|
||||||
val = self._linktype_to_string(link)
|
val = link.name.lower()
|
||||||
dots[dotfile.key][self.key_dotfiles_link] = val
|
dots[dotfile.key][self.key_dotfiles_link] = val
|
||||||
|
|
||||||
# link it to this profile in the yaml file
|
# link it to this profile in the yaml file
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from dotdrop.templategen import Templategen
|
|||||||
from dotdrop.installer import Installer
|
from dotdrop.installer import Installer
|
||||||
from dotdrop.updater import Updater
|
from dotdrop.updater import Updater
|
||||||
from dotdrop.comparator import Comparator
|
from dotdrop.comparator import Comparator
|
||||||
from dotdrop.dotfile import Dotfile
|
|
||||||
from dotdrop.config import Cfg
|
from dotdrop.config import Cfg
|
||||||
from dotdrop.utils import get_tmpdir, remove, strip_home, run
|
from dotdrop.utils import get_tmpdir, remove, strip_home, run
|
||||||
from dotdrop.linktypes import LinkTypes
|
from dotdrop.linktypes import LinkTypes
|
||||||
@@ -60,9 +59,10 @@ def cmd_install(o):
|
|||||||
preactions.append(action)
|
preactions.append(action)
|
||||||
if o.debug:
|
if o.debug:
|
||||||
LOG.dbg('installing {}'.format(dotfile))
|
LOG.dbg('installing {}'.format(dotfile))
|
||||||
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.PARENT:
|
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK:
|
||||||
r = inst.link(t, dotfile.src, dotfile.dst, actions=preactions)
|
r = inst.link(t, dotfile.src, dotfile.dst, actions=preactions)
|
||||||
elif hasattr(dotfile, 'link') and dotfile.link == LinkTypes.CHILDREN:
|
elif hasattr(dotfile, 'link') and \
|
||||||
|
dotfile.link == LinkTypes.LINK_CHILDREN:
|
||||||
r = inst.link_children(t, dotfile.src, dotfile.dst,
|
r = inst.link_children(t, dotfile.src, dotfile.dst,
|
||||||
actions=preactions)
|
actions=preactions)
|
||||||
else:
|
else:
|
||||||
@@ -236,13 +236,16 @@ def cmd_importer(o):
|
|||||||
strip = os.sep
|
strip = os.sep
|
||||||
src = src.lstrip(strip)
|
src = src.lstrip(strip)
|
||||||
|
|
||||||
# create a new dotfile
|
# set the link attribute
|
||||||
dotfile = Dotfile('', dst, src)
|
linktype = o.import_link
|
||||||
|
if linktype == LinkTypes.LINK_CHILDREN and \
|
||||||
linktype = LinkTypes(o.import_link)
|
not os.path.isdir(path):
|
||||||
|
LOG.err('importing \"{}\" failed!'.format(path))
|
||||||
|
ret = False
|
||||||
|
continue
|
||||||
|
|
||||||
if o.debug:
|
if o.debug:
|
||||||
LOG.dbg('new dotfile: {}'.format(dotfile))
|
LOG.dbg('new dotfile: src:{} dst:{}'.format(src, dst))
|
||||||
|
|
||||||
# prepare hierarchy for dotfile
|
# prepare hierarchy for dotfile
|
||||||
srcf = os.path.join(o.dotpath, src)
|
srcf = os.path.join(o.dotpath, src)
|
||||||
@@ -259,19 +262,14 @@ def cmd_importer(o):
|
|||||||
cmd = ['cp', '-R', '-L', dst, srcf]
|
cmd = ['cp', '-R', '-L', dst, srcf]
|
||||||
if o.dry:
|
if o.dry:
|
||||||
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
LOG.dry('would run: {}'.format(' '.join(cmd)))
|
||||||
if linktype == LinkTypes.PARENT:
|
|
||||||
LOG.dry('would symlink {} to {}'.format(srcf, dst))
|
|
||||||
else:
|
else:
|
||||||
r, _ = run(cmd, raw=False, debug=o.debug, checkerr=True)
|
r, _ = run(cmd, raw=False, debug=o.debug, checkerr=True)
|
||||||
if not r:
|
if not r:
|
||||||
LOG.err('importing \"{}\" failed!'.format(path))
|
LOG.err('importing \"{}\" failed!'.format(path))
|
||||||
ret = False
|
ret = False
|
||||||
continue
|
continue
|
||||||
if linktype == LinkTypes.PARENT:
|
retconf, dotfile = o.conf.new(src, dst, o.profile,
|
||||||
remove(dst)
|
linktype, debug=o.debug)
|
||||||
os.symlink(srcf, dst)
|
|
||||||
retconf, dotfile = o.conf.new(dotfile, o.profile,
|
|
||||||
link=linktype, debug=o.debug)
|
|
||||||
if retconf:
|
if retconf:
|
||||||
LOG.sub('\"{}\" imported'.format(path))
|
LOG.sub('\"{}\" imported'.format(path))
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ class Dotfile:
|
|||||||
self.dst = dst
|
self.dst = dst
|
||||||
self.src = src
|
self.src = src
|
||||||
self.link = link
|
self.link = link
|
||||||
|
# ensure link of right type
|
||||||
|
if type(link) != LinkTypes:
|
||||||
|
raise Exception('bad value for link: {}'.format(link))
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
self.trans_r = trans_r
|
self.trans_r = trans_r
|
||||||
self.trans_w = trans_w
|
self.trans_w = trans_w
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ from enum import IntEnum
|
|||||||
|
|
||||||
class LinkTypes(IntEnum):
|
class LinkTypes(IntEnum):
|
||||||
NOLINK = 0
|
NOLINK = 0
|
||||||
PARENT = 1
|
LINK = 1
|
||||||
CHILDREN = 2
|
LINK_CHILDREN = 2
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ CONFIG = 'config.yaml'
|
|||||||
HOMECFG = '~/.config/{}'.format(NAME)
|
HOMECFG = '~/.config/{}'.format(NAME)
|
||||||
|
|
||||||
OPT_LINK = {
|
OPT_LINK = {
|
||||||
'nolink': LinkTypes.NOLINK,
|
LinkTypes.NOLINK.name.lower(): LinkTypes.NOLINK,
|
||||||
'link': LinkTypes.PARENT,
|
LinkTypes.LINK.name.lower(): LinkTypes.LINK,
|
||||||
'link_children': LinkTypes.CHILDREN}
|
LinkTypes.LINK_CHILDREN.name.lower(): LinkTypes.LINK_CHILDREN}
|
||||||
|
|
||||||
BANNER = """ _ _ _
|
BANNER = """ _ _ _
|
||||||
__| | ___ | |_ __| |_ __ ___ _ __
|
__| | ___ | |_ __| |_ __ ___ _ __
|
||||||
@@ -186,12 +186,15 @@ class Options(AttrMonitor):
|
|||||||
|
|
||||||
# import link default value
|
# import link default value
|
||||||
self.import_link = self.link_on_import
|
self.import_link = self.link_on_import
|
||||||
link = self.args['--link']
|
if self.args['--link']:
|
||||||
if link:
|
# overwrite default import link with cli switch
|
||||||
|
link = self.args['--link']
|
||||||
if link not in OPT_LINK.keys():
|
if link not in OPT_LINK.keys():
|
||||||
self.log.err('bad option for --link: {}'.format(link))
|
self.log.err('bad option for --link: {}'.format(link))
|
||||||
sys.exit(USAGE)
|
sys.exit(USAGE)
|
||||||
self.import_link = OPT_LINK[link]
|
self.import_link = OPT_LINK[link]
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('link_import value: {}'.format(self.import_link))
|
||||||
|
|
||||||
# "listfiles" specifics
|
# "listfiles" specifics
|
||||||
self.listfiles_templateonly = self.args['--template']
|
self.listfiles_templateonly = self.args['--template']
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ cd ${ddpath} | ${bin} compare -c ${cfg} -p p1
|
|||||||
cat ${cfg}
|
cat ${cfg}
|
||||||
|
|
||||||
# fail if find some of these entries
|
# fail if find some of these entries
|
||||||
|
echo "========> test for bad entries"
|
||||||
set +e
|
set +e
|
||||||
grep 'link_children: true' ${cfg} >/dev/null && exit 1
|
grep 'link_children: true' ${cfg} >/dev/null && exit 1
|
||||||
grep 'link_children: false' ${cfg} >/dev/null && exit 1
|
grep 'link_children: false' ${cfg} >/dev/null && exit 1
|
||||||
@@ -123,12 +124,13 @@ grep 'link_by_default: false' ${cfg} >/dev/null && exit 1
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# test values have been correctly updated
|
# test values have been correctly updated
|
||||||
|
echo "========> test for updated entries"
|
||||||
dotfiles=`cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 | grep -v '^ '`
|
dotfiles=`cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 | grep -v '^ '`
|
||||||
echo "${dotfiles}" | grep '^f_link ' | grep ', link: parent)'
|
echo "${dotfiles}" | grep '^f_link ' | grep ', link: link)'
|
||||||
echo "${dotfiles}" | grep '^f_nolink ' | grep ', link: nolink)'
|
echo "${dotfiles}" | grep '^f_nolink ' | grep ', link: nolink)'
|
||||||
echo "${dotfiles}" | grep '^f_nolink1 ' | grep ', link: nolink)'
|
echo "${dotfiles}" | grep '^f_nolink1 ' | grep ', link: nolink)'
|
||||||
echo "${dotfiles}" | grep '^f_children ' | grep ', link: children)'
|
echo "${dotfiles}" | grep '^f_children ' | grep ', link: link_children)'
|
||||||
echo "${dotfiles}" | grep '^f_children2 ' | grep ', link: children)'
|
echo "${dotfiles}" | grep '^f_children2 ' | grep ', link: link_children)'
|
||||||
echo "${dotfiles}" | grep '^f_children3 ' | grep ', link: nolink)'
|
echo "${dotfiles}" | grep '^f_children3 ' | grep ', link: nolink)'
|
||||||
|
|
||||||
## CLEANING
|
## CLEANING
|
||||||
|
|||||||
136
tests-ng/import-link-children.sh
Executable file
136
tests-ng/import-link-children.sh
Executable file
@@ -0,0 +1,136 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
# Copyright (c) 2017, deadc0de6
|
||||||
|
#
|
||||||
|
# test importing link_children
|
||||||
|
# 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'`
|
||||||
|
|
||||||
|
# dotpath
|
||||||
|
dotpath="${tmps}/dotfiles"
|
||||||
|
mkdir -p ${dotpath}
|
||||||
|
|
||||||
|
# create the dotfile to import
|
||||||
|
dt="${tmpd}/directory"
|
||||||
|
mkdir -p ${dt}
|
||||||
|
# subdir
|
||||||
|
dtsub1="${dt}/sub1"
|
||||||
|
mkdir -p ${dtsub1}
|
||||||
|
dtsub2="${dt}/sub2"
|
||||||
|
mkdir -p ${dtsub2}
|
||||||
|
dtsub3="${dtsub1}/subsub1"
|
||||||
|
mkdir -p ${dtsub3}
|
||||||
|
# files
|
||||||
|
f1="${dt}/file"
|
||||||
|
subf1="${dtsub1}/file"
|
||||||
|
subf2="${dtsub2}/file"
|
||||||
|
subf3="${dtsub3}/file"
|
||||||
|
touch ${f1} ${subf1} ${subf2} ${subf3}
|
||||||
|
|
||||||
|
# create the config file
|
||||||
|
cfg="${tmps}/config.yaml"
|
||||||
|
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 -V --link=link_children ${dt}
|
||||||
|
|
||||||
|
# check is set to link_children
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${dt}`")
|
||||||
|
echo ${line} | grep 'link: link_children'
|
||||||
|
|
||||||
|
# checks file exists in dotpath
|
||||||
|
[ ! -e ${dotpath}/${dt} ] && echo "dotfile not imported" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${dtsub1} ] && echo "sub1 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${dtsub2} ] && echo "sub2 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${dtsub3} ] && echo "sub3 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${f1} ] && echo "f1 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${subf1} ] && echo "subf1 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${subf2} ] && echo "subf2 not found in dotpath" && exit 1
|
||||||
|
[ ! -e ${dotpath}/${subf3} ] && echo "subf3 not found in dotpath" && exit 1
|
||||||
|
|
||||||
|
# checks file exists in fs
|
||||||
|
[ ! -e ${dt} ] && echo "dotfile not imported" && exit 1
|
||||||
|
[ ! -e ${dtsub1} ] && echo "sub1 not found in fs" && exit 1
|
||||||
|
[ ! -e ${dtsub2} ] && echo "sub2 not found in fs" && exit 1
|
||||||
|
[ ! -e ${dtsub3} ] && echo "sub3 not found in fs" && exit 1
|
||||||
|
[ ! -e ${f1} ] && echo "f1 not found in fs" && exit 1
|
||||||
|
[ ! -e ${subf1} ] && echo "subf1 not found in fs" && exit 1
|
||||||
|
[ ! -e ${subf2} ] && echo "subf2 not found in fs" && exit 1
|
||||||
|
[ ! -e ${subf3} ] && echo "subf3 not found in fs" && exit 1
|
||||||
|
|
||||||
|
# install
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
|
||||||
|
# checks file have correct type in fs
|
||||||
|
file ${f1}
|
||||||
|
[ ! -h ${f1} ] && echo "f1 is not a symlink" && exit 1
|
||||||
|
[ -h ${subf1} ] && echo "subf1 is not a regular file" && exit 1
|
||||||
|
[ -h ${subf2} ] && echo "subf2 is not a regular file" && exit 1
|
||||||
|
[ -h ${subf3} ] && echo "subf3 is not a regular file" && exit 1
|
||||||
|
[ ! -h ${dtsub1} ] && echo "dtsub1 is not a symlink" && exit 1
|
||||||
|
[ ! -h ${dtsub2} ] && echo "dtsub2 is not a symlink" && exit 1
|
||||||
|
[ -h ${dtsub3} ] && echo "dtsub3 is not a regular directory" && exit 1
|
||||||
|
|
||||||
|
echo "DOTPATH"
|
||||||
|
tree ${tmps}/dotfiles
|
||||||
|
echo "FILESYSTEM"
|
||||||
|
tree ${dt}
|
||||||
|
|
||||||
|
## CLEANING
|
||||||
|
rm -rf ${tmps} ${tmpd}
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
exit 0
|
||||||
479
tests-ng/link-value-tests.sh
Executable file
479
tests-ng/link-value-tests.sh
Executable file
@@ -0,0 +1,479 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
|
# Copyright (c) 2019, deadc0de6
|
||||||
|
#
|
||||||
|
# test the behavior when playing with link_dotfile_default
|
||||||
|
# and link_on_import on import
|
||||||
|
# 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'`
|
||||||
|
|
||||||
|
# create the config file
|
||||||
|
cfg="${tmps}/config.yaml"
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with all default"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: nolink
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: nolink
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=nolink and --link=link"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: nolink
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=link
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: link'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ ! -h ${df} ] && echo "not symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: link
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: link'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ ! -h ${df} ] && echo "not symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: link
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=nolink and link_dotfile_default=link"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: nolink
|
||||||
|
link_dotfile_default: link
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with link_on_import=link and link_dotfile_default=nolink and --link=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: link
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V --link=nolink
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: nolink'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with all default and --link=link"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} --link=link -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "f_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: link'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ ! -h ${df} ] && echo "not a symlink" && exit 1
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with all default and --link=link_children"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
set +e
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} --link=link_children -p p1 ${df} -V
|
||||||
|
[ "$?" = "0" ] && echo "link_children with file should fail" && exit 1
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
echo -e "\n======> import with all default and --link=link_children"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
mkdir -p ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert/file
|
||||||
|
mkdir -p ${tmpd}/qwert/directory
|
||||||
|
echo "test" > ${tmpd}/qwert/directory/file
|
||||||
|
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} --link=link_children -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: link_children'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is a symlink" && exit 1
|
||||||
|
[ ! -h ${df}/file ] && echo "file is not a symlink" && exit 1
|
||||||
|
[ ! -h ${df}/directory ] && echo "directory is not a symlink" && exit 1
|
||||||
|
[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1
|
||||||
|
|
||||||
|
echo -e "\n======> import with link_on_import=link_children and link_dotfile_default=nolink"
|
||||||
|
# create the source
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
mkdir -p ${tmpd}/qwert
|
||||||
|
echo "test" > ${tmpd}/qwert/file
|
||||||
|
mkdir -p ${tmpd}/qwert/directory
|
||||||
|
echo "test" > ${tmpd}/qwert/directory/file
|
||||||
|
|
||||||
|
# clean
|
||||||
|
rm -rf ${tmps}/dotfiles
|
||||||
|
mkdir -p ${tmps}/dotfiles
|
||||||
|
# config file
|
||||||
|
cat > ${cfg} << _EOF
|
||||||
|
config:
|
||||||
|
backup: true
|
||||||
|
create: true
|
||||||
|
dotpath: dotfiles
|
||||||
|
link_on_import: link_children
|
||||||
|
link_dotfile_default: nolink
|
||||||
|
dotfiles:
|
||||||
|
profiles:
|
||||||
|
_EOF
|
||||||
|
|
||||||
|
# import
|
||||||
|
df="${tmpd}/qwert"
|
||||||
|
cd ${ddpath} | ${bin} import -c ${cfg} -p p1 ${df} -V
|
||||||
|
|
||||||
|
# checks
|
||||||
|
cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V
|
||||||
|
line=$(cd ${ddpath} | ${bin} listfiles -c ${cfg} -p p1 -V | grep "d_`basename ${df}`")
|
||||||
|
echo ${line} | grep 'link: link_children'
|
||||||
|
|
||||||
|
# try to install
|
||||||
|
rm -rf ${tmpd}/qwert
|
||||||
|
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||||
|
[ ! -e ${df} ] && echo "does not exist" && exit 1
|
||||||
|
[ -h ${df} ] && echo "is a symlink" && exit 1
|
||||||
|
[ ! -h ${df}/file ] && echo "file is not a symlink" && exit 1
|
||||||
|
[ ! -h ${df}/directory ] && echo "directory is not a symlink" && exit 1
|
||||||
|
[ -h ${df}/directory/file ] && echo "directory/file is a symlink" && exit 1
|
||||||
|
|
||||||
|
## CLEANING
|
||||||
|
rm -rf ${tmps} ${tmpd}
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
exit 0
|
||||||
@@ -50,15 +50,19 @@ class TestConfig(unittest.TestCase):
|
|||||||
self.assertTrue(conf.dump() != '')
|
self.assertTrue(conf.dump() != '')
|
||||||
|
|
||||||
def test_def_link(self):
|
def test_def_link(self):
|
||||||
self._test_link_import('nolink', LinkTypes.PARENT, 'link')
|
self._test_link_import('nolink', LinkTypes.LINK, 'link')
|
||||||
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
|
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
|
||||||
self._test_link_import('nolink', LinkTypes.CHILDREN, 'link_children')
|
self._test_link_import('nolink',
|
||||||
self._test_link_import('link', LinkTypes.PARENT, 'link')
|
LinkTypes.LINK_CHILDREN,
|
||||||
|
'link_children')
|
||||||
|
self._test_link_import('link', LinkTypes.LINK, 'link')
|
||||||
self._test_link_import('link', LinkTypes.NOLINK, 'nolink')
|
self._test_link_import('link', LinkTypes.NOLINK, 'nolink')
|
||||||
self._test_link_import('link', LinkTypes.CHILDREN, 'link_children')
|
self._test_link_import('link',
|
||||||
self._test_link_import('link_children', LinkTypes.PARENT, 'link')
|
LinkTypes.LINK_CHILDREN,
|
||||||
|
'link_children')
|
||||||
|
self._test_link_import('link_children', LinkTypes.LINK, 'link')
|
||||||
self._test_link_import('link_children', LinkTypes.NOLINK, 'nolink')
|
self._test_link_import('link_children', LinkTypes.NOLINK, 'nolink')
|
||||||
self._test_link_import('link_children', LinkTypes.CHILDREN,
|
self._test_link_import('link_children', LinkTypes.LINK_CHILDREN,
|
||||||
'link_children')
|
'link_children')
|
||||||
self._test_link_import_fail('whatever')
|
self._test_link_import_fail('whatever')
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class TestImport(unittest.TestCase):
|
|||||||
o.import_path = dfiles
|
o.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(o)
|
||||||
# import symlink
|
# import symlink
|
||||||
o.import_link = LinkTypes.PARENT
|
o.import_link = LinkTypes.LINK
|
||||||
sfiles = [dotfile6, dotfile7]
|
sfiles = [dotfile6, dotfile7]
|
||||||
o.import_path = sfiles
|
o.import_path = sfiles
|
||||||
cmd_importer(o)
|
cmd_importer(o)
|
||||||
@@ -191,12 +191,6 @@ class TestImport(unittest.TestCase):
|
|||||||
sub4)
|
sub4)
|
||||||
self.assertTrue(os.path.exists(s4))
|
self.assertTrue(os.path.exists(s4))
|
||||||
|
|
||||||
# test symlink on filesystem
|
|
||||||
self.assertTrue(os.path.islink(dotfile6))
|
|
||||||
self.assertTrue(os.path.realpath(dotfile6) == indt6)
|
|
||||||
self.assertTrue(os.path.islink(dotfile7))
|
|
||||||
self.assertTrue(os.path.realpath(dotfile7) == indt7)
|
|
||||||
|
|
||||||
cmd_list_profiles(o)
|
cmd_list_profiles(o)
|
||||||
cmd_list_files(o)
|
cmd_list_files(o)
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ from dotdrop.installer import Installer
|
|||||||
from dotdrop.action import Action
|
from dotdrop.action import Action
|
||||||
from dotdrop.dotdrop import cmd_install
|
from dotdrop.dotdrop import cmd_install
|
||||||
from dotdrop.options import BACKUP_SUFFIX
|
from dotdrop.options import BACKUP_SUFFIX
|
||||||
from dotdrop.linktypes import LinkTypes
|
|
||||||
from dotdrop.utils import header
|
from dotdrop.utils import header
|
||||||
|
from dotdrop.linktypes import LinkTypes
|
||||||
|
|
||||||
|
|
||||||
class TestInstall(unittest.TestCase):
|
class TestInstall(unittest.TestCase):
|
||||||
@@ -57,12 +57,7 @@ exec bspwm
|
|||||||
f.write(' {}:\n'.format(d.key))
|
f.write(' {}:\n'.format(d.key))
|
||||||
f.write(' dst: {}\n'.format(d.dst))
|
f.write(' dst: {}\n'.format(d.dst))
|
||||||
f.write(' src: {}\n'.format(d.src))
|
f.write(' src: {}\n'.format(d.src))
|
||||||
if d.link == LinkTypes.CHILDREN:
|
f.write(' link: {}\n'.format(d.link.name.lower()))
|
||||||
f.write(' link_children: {}\n'
|
|
||||||
.format(str(d.link == LinkTypes.CHILDREN).lower()))
|
|
||||||
else:
|
|
||||||
f.write(' link: {}\n'
|
|
||||||
.format(str(d.link == LinkTypes.PARENT).lower()))
|
|
||||||
if len(d.actions) > 0:
|
if len(d.actions) > 0:
|
||||||
f.write(' actions:\n')
|
f.write(' actions:\n')
|
||||||
for action in d.actions:
|
for action in d.actions:
|
||||||
@@ -122,7 +117,8 @@ exec bspwm
|
|||||||
f5, c5 = create_random_file(tmp)
|
f5, c5 = create_random_file(tmp)
|
||||||
dst5 = os.path.join(dst, get_string(6))
|
dst5 = os.path.join(dst, get_string(6))
|
||||||
self.addCleanup(clean, dst5)
|
self.addCleanup(clean, dst5)
|
||||||
d5 = Dotfile(get_string(6), dst5, os.path.basename(f5), link=True)
|
d5 = Dotfile(get_string(6), dst5,
|
||||||
|
os.path.basename(f5), link=LinkTypes.LINK)
|
||||||
|
|
||||||
# create the dotfile directories in dotdrop
|
# create the dotfile directories in dotdrop
|
||||||
dir1 = create_dir(os.path.join(tmp, get_string(6)))
|
dir1 = create_dir(os.path.join(tmp, get_string(6)))
|
||||||
@@ -148,7 +144,8 @@ exec bspwm
|
|||||||
sub4, _ = create_random_file(dir2)
|
sub4, _ = create_random_file(dir2)
|
||||||
self.assertTrue(os.path.exists(sub4))
|
self.assertTrue(os.path.exists(sub4))
|
||||||
# make up the dotfile
|
# make up the dotfile
|
||||||
d7 = Dotfile(get_string(6), dst7, os.path.basename(dir2), link=True)
|
d7 = Dotfile(get_string(6), dst7,
|
||||||
|
os.path.basename(dir2), link=LinkTypes.LINK)
|
||||||
|
|
||||||
# to test actions
|
# to test actions
|
||||||
value = get_string(12)
|
value = get_string(12)
|
||||||
|
|||||||
Reference in New Issue
Block a user