mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 18:34:48 +00:00
allow empty src/dst for dotfiles
This commit is contained in:
@@ -221,19 +221,29 @@ class CfgYaml:
|
||||
for dotfile in self.dotfiles.values():
|
||||
# src
|
||||
src = dotfile[self.key_dotfile_src]
|
||||
new = t.generate_string(src)
|
||||
if new != src and self.debug:
|
||||
self.log.dbg('dotfile: {} -> {}'.format(src, new))
|
||||
src = new
|
||||
src = os.path.join(self.settings[self.key_settings_dotpath], src)
|
||||
dotfile[self.key_dotfile_src] = self._norm_path(src)
|
||||
if not src:
|
||||
dotfile[self.key_dotfile_src] = ''
|
||||
else:
|
||||
new = t.generate_string(src)
|
||||
if new != src and self.debug:
|
||||
msg = 'dotfile src: \"{}\" -> \"{}\"'.format(src, new)
|
||||
self.log.dbg(msg)
|
||||
src = new
|
||||
src = os.path.join(self.settings[self.key_settings_dotpath],
|
||||
src)
|
||||
dotfile[self.key_dotfile_src] = self._norm_path(src)
|
||||
|
||||
# dst
|
||||
dst = dotfile[self.key_dotfile_dst]
|
||||
new = t.generate_string(dst)
|
||||
if new != dst and self.debug:
|
||||
self.log.dbg('dotfile: {} -> {}'.format(dst, new))
|
||||
dst = new
|
||||
dotfile[self.key_dotfile_dst] = self._norm_path(dst)
|
||||
if not dst:
|
||||
dotfile[self.key_dotfile_dst] = ''
|
||||
else:
|
||||
new = t.generate_string(dst)
|
||||
if new != dst and self.debug:
|
||||
msg = 'dotfile dst: \"{}\" -> \"{}\"'.format(dst, new)
|
||||
self.log.dbg(msg)
|
||||
dst = new
|
||||
dotfile[self.key_dotfile_dst] = self._norm_path(dst)
|
||||
|
||||
def _rec_resolve_vars(self, variables):
|
||||
"""recursive resolve variables"""
|
||||
@@ -980,6 +990,8 @@ class CfgYaml:
|
||||
|
||||
def _norm_path(self, path):
|
||||
"""resolve a path either absolute or relative to config path"""
|
||||
if not path:
|
||||
return path
|
||||
path = os.path.expanduser(path)
|
||||
if not os.path.isabs(path):
|
||||
d = os.path.dirname(self.path)
|
||||
|
||||
@@ -68,7 +68,11 @@ class Installer:
|
||||
- False, None : ignored
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.dbg('install {} to {}'.format(src, dst))
|
||||
self.log.dbg('install \"{}\" to \"{}\"'.format(src, dst))
|
||||
if not dst or not src:
|
||||
if self.debug:
|
||||
self.log.dbg('empty dst for {}'.format(src))
|
||||
return True, None
|
||||
self.action_executed = False
|
||||
src = os.path.join(self.base, os.path.expanduser(src))
|
||||
if not os.path.exists(src):
|
||||
@@ -107,7 +111,11 @@ class Installer:
|
||||
- False, None : ignored
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.dbg('link {} to {}'.format(src, dst))
|
||||
self.log.dbg('link \"{}\" to \"{}\"'.format(src, dst))
|
||||
if not dst or not src:
|
||||
if self.debug:
|
||||
self.log.dbg('empty dst for {}'.format(src))
|
||||
return True, None
|
||||
self.action_executed = False
|
||||
src = os.path.normpath(os.path.join(self.base,
|
||||
os.path.expanduser(src)))
|
||||
@@ -144,7 +152,11 @@ class Installer:
|
||||
- False, None, ignored
|
||||
"""
|
||||
if self.debug:
|
||||
self.log.dbg('link_children {} to {}'.format(src, dst))
|
||||
self.log.dbg('link_children \"{}\" to \"{}\"'.format(src, dst))
|
||||
if not dst or not src:
|
||||
if self.debug:
|
||||
self.log.dbg('empty dst for {}'.format(src))
|
||||
return True, None
|
||||
self.action_executed = False
|
||||
parent = os.path.join(self.base, os.path.expanduser(src))
|
||||
|
||||
|
||||
87
tests-ng/install-empty.sh
Executable file
87
tests-ng/install-empty.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2019, deadc0de6
|
||||
#
|
||||
# test install empty dst or empty src
|
||||
# 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 "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)"
|
||||
|
||||
################################################################
|
||||
# this is the test
|
||||
################################################################
|
||||
|
||||
# dotdrop directory
|
||||
basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
echo "[+] dotdrop dir: ${basedir}"
|
||||
echo "[+] dotpath dir: ${basedir}/dotfiles"
|
||||
|
||||
# create the config file
|
||||
cfg="${basedir}/config.yaml"
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dotfiles:
|
||||
f_x:
|
||||
src: /tmp/x
|
||||
dst:
|
||||
f_y:
|
||||
src:
|
||||
dst: /tmp/y
|
||||
f_z:
|
||||
src:
|
||||
dst:
|
||||
profiles:
|
||||
qube:
|
||||
dotfiles:
|
||||
- f_x
|
||||
- f_y
|
||||
- f_z
|
||||
|
||||
_EOF
|
||||
|
||||
echo "[+] install"
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} --verbose | grep '^3 dotfile(s) installed.$'
|
||||
[ "$?" != "0" ] && exit 1
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${basedir}
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user