mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 22:39:43 +00:00
fix tests
This commit is contained in:
@@ -58,7 +58,7 @@ class CfgYaml:
|
||||
key_dotfile_actions = 'actions'
|
||||
key_dotfile_link_children = 'link_children'
|
||||
key_dotfile_noempty = 'ignoreempty'
|
||||
key_dotfile_notemplate = 'notemplate'
|
||||
key_dotfile_template = 'template'
|
||||
|
||||
# profile
|
||||
key_profile_dotfiles = 'dotfiles'
|
||||
@@ -84,7 +84,7 @@ class CfgYaml:
|
||||
key_settings_noempty = Settings.key_ignoreempty
|
||||
key_settings_minversion = Settings.key_minversion
|
||||
key_imp_link = Settings.key_link_on_import
|
||||
key_settings_notemplate = Settings.key_template_dotfile_default
|
||||
key_settings_template = Settings.key_template_dotfile_default
|
||||
|
||||
# link values
|
||||
lnk_nolink = LinkTypes.NOLINK.name.lower()
|
||||
@@ -599,10 +599,10 @@ class CfgYaml:
|
||||
if self.key_dotfile_noempty not in v:
|
||||
val = self.settings.get(self.key_settings_noempty, False)
|
||||
v[self.key_dotfile_noempty] = val
|
||||
# apply notemplate if undefined
|
||||
if self.key_dotfile_notemplate not in v:
|
||||
val = self.settings.get(self.key_settings_notemplate, False)
|
||||
v[self.key_dotfile_notemplate] = val
|
||||
# apply template if undefined
|
||||
if self.key_dotfile_template not in v:
|
||||
val = self.settings.get(self.key_settings_template, True)
|
||||
v[self.key_dotfile_template] = val
|
||||
|
||||
return new
|
||||
|
||||
|
||||
@@ -130,12 +130,12 @@ def cmd_install(o):
|
||||
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK:
|
||||
r, err = inst.link(t, dotfile.src, dotfile.dst,
|
||||
actionexec=pre_actions_exec,
|
||||
notemplate=dotfile.notemplate)
|
||||
template=dotfile.template)
|
||||
elif hasattr(dotfile, 'link') and \
|
||||
dotfile.link == LinkTypes.LINK_CHILDREN:
|
||||
r, err = inst.link_children(t, dotfile.src, dotfile.dst,
|
||||
actionexec=pre_actions_exec,
|
||||
notemplate=dotfile.notemplate)
|
||||
template=dotfile.template)
|
||||
else:
|
||||
src = dotfile.src
|
||||
tmp = None
|
||||
@@ -150,7 +150,7 @@ def cmd_install(o):
|
||||
actionexec=pre_actions_exec,
|
||||
noempty=dotfile.noempty,
|
||||
ignore=ignores,
|
||||
notemplate=dotfile.notemplate)
|
||||
template=dotfile.template)
|
||||
if tmp:
|
||||
tmp = os.path.join(o.dotpath, tmp)
|
||||
if os.path.exists(tmp):
|
||||
@@ -268,7 +268,7 @@ def cmd_compare(o, tmp):
|
||||
|
||||
# install dotfile to temporary dir and compare
|
||||
ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst,
|
||||
notemplate=dotfile.notemplate)
|
||||
template=dotfile.template)
|
||||
if not ret:
|
||||
# failed to install to tmp
|
||||
line = '=> compare {}: error'
|
||||
|
||||
@@ -16,13 +16,13 @@ class Dotfile(DictParser):
|
||||
key_noempty = 'ignoreempty'
|
||||
key_trans_r = 'trans_read'
|
||||
key_trans_w = 'trans_write'
|
||||
key_notemplate = 'notemplate'
|
||||
key_template = 'template'
|
||||
|
||||
def __init__(self, key, dst, src,
|
||||
actions=[], trans_r=None, trans_w=None,
|
||||
link=LinkTypes.NOLINK, noempty=False,
|
||||
cmpignore=[], upignore=[],
|
||||
instignore=[], notemplate=False):
|
||||
instignore=[], template=True):
|
||||
"""
|
||||
constructor
|
||||
@key: dotfile key
|
||||
@@ -36,7 +36,7 @@ class Dotfile(DictParser):
|
||||
@upignore: patterns to ignore when updating
|
||||
@cmpignore: patterns to ignore when comparing
|
||||
@instignore: patterns to ignore when installing
|
||||
@notemplate: disable template for this dotfile
|
||||
@template: template this dotfile
|
||||
"""
|
||||
self.actions = actions
|
||||
self.dst = dst
|
||||
@@ -49,7 +49,7 @@ class Dotfile(DictParser):
|
||||
self.upignore = upignore
|
||||
self.cmpignore = cmpignore
|
||||
self.instignore = instignore
|
||||
self.notemplate = notemplate
|
||||
self.template = template
|
||||
|
||||
if self.link != LinkTypes.NOLINK and \
|
||||
(
|
||||
@@ -94,7 +94,7 @@ class Dotfile(DictParser):
|
||||
value['noempty'] = value.get(cls.key_noempty, False)
|
||||
value['trans_r'] = value.get(cls.key_trans_r)
|
||||
value['trans_w'] = value.get(cls.key_trans_w)
|
||||
value['notemplate'] = value.get(cls.key_notemplate, False)
|
||||
value['template'] = value.get(cls.key_template, True)
|
||||
# remove old entries
|
||||
value.pop(cls.key_noempty, None)
|
||||
value.pop(cls.key_trans_r, None)
|
||||
@@ -112,7 +112,7 @@ class Dotfile(DictParser):
|
||||
msg += ', src:\"{}\"'.format(self.src)
|
||||
msg += ', dst:\"{}\"'.format(self.dst)
|
||||
msg += ', link:\"{}\"'.format(str(self.link))
|
||||
msg += ', template:{}'.format(not self.notemplate)
|
||||
msg += ', template:{}'.format(self.template)
|
||||
return msg
|
||||
|
||||
def prt(self):
|
||||
@@ -122,7 +122,7 @@ class Dotfile(DictParser):
|
||||
out += '\n{}src: \"{}\"'.format(indent, self.src)
|
||||
out += '\n{}dst: \"{}\"'.format(indent, self.dst)
|
||||
out += '\n{}link: \"{}\"'.format(indent, str(self.link))
|
||||
out += '\n{}notemplate: \"{}\"'.format(indent, str(self.notemplate))
|
||||
out += '\n{}template: \"{}\"'.format(indent, str(self.template))
|
||||
|
||||
out += '\n{}pre-action:'.format(indent)
|
||||
some = self.get_pre_actions()
|
||||
|
||||
@@ -66,7 +66,7 @@ class Installer:
|
||||
|
||||
def install(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[], notemplate=False):
|
||||
ignore=[], template=True):
|
||||
"""
|
||||
install src to dst using a template
|
||||
@templater: the templater object
|
||||
@@ -75,7 +75,7 @@ class Installer:
|
||||
@actionexec: action executor callback
|
||||
@noempty: render empty template flag
|
||||
@ignore: pattern to ignore when installing
|
||||
@notemplate: do not template
|
||||
@template: template this dotfile
|
||||
|
||||
return
|
||||
- True, None : success
|
||||
@@ -108,22 +108,22 @@ class Installer:
|
||||
b, e = self._install_dir(templater, src, dst,
|
||||
actionexec=actionexec,
|
||||
noempty=noempty, ignore=ignore,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
return self._log_install(b, e)
|
||||
b, e = self._install_file(templater, src, dst,
|
||||
actionexec=actionexec,
|
||||
noempty=noempty, ignore=ignore,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
return self._log_install(b, e)
|
||||
|
||||
def link(self, templater, src, dst, actionexec=None, notemplate=False):
|
||||
def link(self, templater, src, dst, actionexec=None, template=True):
|
||||
"""
|
||||
set src as the link target of dst
|
||||
@templater: the templater
|
||||
@src: dotfile source path in dotpath
|
||||
@dst: dotfile destination path in the FS
|
||||
@actionexec: action executor callback
|
||||
@notemplate: do no template
|
||||
@template: template this dotfile
|
||||
|
||||
return
|
||||
- True, None : success
|
||||
@@ -146,16 +146,16 @@ class Installer:
|
||||
if self.totemp:
|
||||
# ignore actions
|
||||
b, e = self.install(templater, src, dst, actionexec=None,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
return self._log_install(b, e)
|
||||
|
||||
if not notemplate and Templategen.is_template(src):
|
||||
if template and Templategen.is_template(src):
|
||||
if self.debug:
|
||||
self.log.dbg('dotfile is a template')
|
||||
self.log.dbg('install to {} and symlink'.format(self.workdir))
|
||||
tmp = self._pivot_path(dst, self.workdir, striphome=True)
|
||||
i, err = self.install(templater, src, tmp, actionexec=actionexec,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
if not i and not os.path.exists(tmp):
|
||||
return self._log_install(i, err)
|
||||
src = tmp
|
||||
@@ -163,14 +163,14 @@ class Installer:
|
||||
return self._log_install(b, e)
|
||||
|
||||
def link_children(self, templater, src, dst, actionexec=None,
|
||||
notemplate=False):
|
||||
template=True):
|
||||
"""
|
||||
link all dotfiles in a given directory
|
||||
@templater: the templater
|
||||
@src: dotfile source path in dotpath
|
||||
@dst: dotfile destination path in the FS
|
||||
@actionexec: action executor callback
|
||||
@notemplate: do not template
|
||||
@template: template this dotfile
|
||||
|
||||
return
|
||||
- True, None: success
|
||||
@@ -230,14 +230,14 @@ class Installer:
|
||||
if self.debug:
|
||||
self.log.dbg('symlink child {} to {}'.format(src, dst))
|
||||
|
||||
if not notemplate and Templategen.is_template(src):
|
||||
if template and Templategen.is_template(src):
|
||||
if self.debug:
|
||||
self.log.dbg('dotfile is a template')
|
||||
self.log.dbg('install to {} and symlink'
|
||||
.format(self.workdir))
|
||||
tmp = self._pivot_path(dst, self.workdir, striphome=True)
|
||||
r, e = self.install(templater, src, tmp, actionexec=actionexec,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
if not r and e and not os.path.exists(tmp):
|
||||
continue
|
||||
src = tmp
|
||||
@@ -318,13 +318,13 @@ class Installer:
|
||||
|
||||
def _install_file(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[], notemplate=False):
|
||||
ignore=[], template=True):
|
||||
"""install src to dst when is a file"""
|
||||
if self.debug:
|
||||
self.log.dbg('deploy file: {}'.format(src))
|
||||
self.log.dbg('ignore empty: {}'.format(noempty))
|
||||
self.log.dbg('ignore pattern: {}'.format(ignore))
|
||||
self.log.dbg('no template: {}'.format(notemplate))
|
||||
self.log.dbg('template: {}'.format(template))
|
||||
self.log.dbg('no empty: {}'.format(noempty))
|
||||
|
||||
if utils.must_ignore([src, dst], ignore, debug=self.debug):
|
||||
@@ -338,7 +338,7 @@ class Installer:
|
||||
return False, err
|
||||
|
||||
# handle the file
|
||||
if not notemplate:
|
||||
if template:
|
||||
# template the file
|
||||
saved = templater.add_tmp_vars(self._get_tmp_file_vars(src, dst))
|
||||
try:
|
||||
@@ -389,7 +389,7 @@ class Installer:
|
||||
|
||||
def _install_dir(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[], notemplate=False):
|
||||
ignore=[], template=True):
|
||||
"""install src to dst when is a directory"""
|
||||
if self.debug:
|
||||
self.log.dbg('install dir {}'.format(src))
|
||||
@@ -409,7 +409,7 @@ class Installer:
|
||||
actionexec=actionexec,
|
||||
noempty=noempty,
|
||||
ignore=ignore,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
if not res and err:
|
||||
# error occured
|
||||
ret = res, err
|
||||
@@ -424,7 +424,7 @@ class Installer:
|
||||
actionexec=actionexec,
|
||||
noempty=noempty,
|
||||
ignore=ignore,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
if not res and err:
|
||||
# error occured
|
||||
ret = res, err
|
||||
@@ -562,13 +562,13 @@ class Installer:
|
||||
self.action_executed = True
|
||||
return ret, err
|
||||
|
||||
def _install_to_temp(self, templater, src, dst, tmpdir, notemplate=False):
|
||||
def _install_to_temp(self, templater, src, dst, tmpdir, template=True):
|
||||
"""install a dotfile to a tempdir"""
|
||||
tmpdst = self._pivot_path(dst, tmpdir)
|
||||
r = self.install(templater, src, tmpdst, notemplate=notemplate)
|
||||
r = self.install(templater, src, tmpdst, template=template)
|
||||
return r, tmpdst
|
||||
|
||||
def install_to_temp(self, templater, tmpdir, src, dst, notemplate=False):
|
||||
def install_to_temp(self, templater, tmpdir, src, dst, template=True):
|
||||
"""install a dotfile to a tempdir"""
|
||||
ret = False
|
||||
tmpdst = ''
|
||||
@@ -587,7 +587,7 @@ class Installer:
|
||||
self.log.dbg('tmp install {} (defined dst: {})'.format(src, dst))
|
||||
# install the dotfile to a temp directory for comparing
|
||||
r, tmpdst = self._install_to_temp(templater, src, dst, tmpdir,
|
||||
notemplate=notemplate)
|
||||
template=template)
|
||||
ret, err = r
|
||||
if self.debug:
|
||||
self.log.dbg('tmp installed in {}'.format(tmpdst))
|
||||
|
||||
@@ -51,7 +51,7 @@ class Settings(DictParser):
|
||||
workdir='~/.config/dotdrop', showdiff=False,
|
||||
minversion=None, func_file=[], filter_file=[],
|
||||
diff_command='diff -r -u {0} {1}',
|
||||
template_dotfile_default=False):
|
||||
template_dotfile_default=True):
|
||||
self.backup = backup
|
||||
self.banner = banner
|
||||
self.create = create
|
||||
|
||||
@@ -63,7 +63,7 @@ config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
template_dotfile_default: true
|
||||
template_dotfile_default: false
|
||||
dotfiles:
|
||||
f_f1:
|
||||
dst: ${tmpd}/f1
|
||||
@@ -83,6 +83,10 @@ dotfiles:
|
||||
dst: ${tmpd}/fl
|
||||
src: fl
|
||||
link: link
|
||||
f_fn:
|
||||
dst: ${tmpd}/fn
|
||||
src: fn
|
||||
template: true
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
@@ -91,6 +95,7 @@ profiles:
|
||||
- d_d2
|
||||
- d_d3
|
||||
- f_fl
|
||||
- f_fn
|
||||
_EOF
|
||||
#cat ${cfg}
|
||||
|
||||
@@ -116,11 +121,16 @@ echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/dir3/s2/f2
|
||||
# create the linked dotfile
|
||||
echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/fl
|
||||
|
||||
# create the normal dotfile
|
||||
echo "before" > ${tmps}/dotfiles/fn
|
||||
echo "{#@@ should not be stripped @@#}" >> ${tmps}/dotfiles/fn
|
||||
echo "after" > ${tmps}/dotfiles/fn
|
||||
|
||||
# install
|
||||
echo "doing globally"
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
# simple file
|
||||
echo "doing globally"
|
||||
echo "* test simple file"
|
||||
[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1
|
||||
grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1)
|
||||
@@ -156,6 +166,11 @@ echo "* test linked file"
|
||||
[ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1
|
||||
grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1)
|
||||
|
||||
# normal dotfile
|
||||
echo "* normal dotfile"
|
||||
[ ! -e ${tmpd}/fn ] && echo 'not installed' && exit 1
|
||||
grep 'should not be stripped' ${tmpd}/fn && echo "no templated" && exit 1
|
||||
|
||||
# through the dotfile
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
@@ -167,21 +182,29 @@ dotfiles:
|
||||
f_f1:
|
||||
dst: ${tmpd}/f1
|
||||
src: f1
|
||||
template: false
|
||||
d_d1:
|
||||
dst: ${tmpd}/dir1
|
||||
src: dir1
|
||||
template: false
|
||||
d_d2:
|
||||
dst: ${tmpd}/dir2
|
||||
src: dir2
|
||||
link: link
|
||||
template: false
|
||||
d_d3:
|
||||
dst: ${tmpd}/dir3
|
||||
src: dir3
|
||||
link: link_children
|
||||
template: false
|
||||
f_fl:
|
||||
dst: ${tmpd}/fl
|
||||
src: fl
|
||||
link: link
|
||||
template: false
|
||||
f_fn:
|
||||
dst: ${tmpd}/fn
|
||||
src: fn
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
@@ -190,6 +213,7 @@ profiles:
|
||||
- d_d2
|
||||
- d_d3
|
||||
- f_fl
|
||||
- f_fn
|
||||
_EOF
|
||||
#cat ${cfg}
|
||||
|
||||
@@ -197,10 +221,10 @@ _EOF
|
||||
rm -rf ${tmpd}/*
|
||||
|
||||
# install
|
||||
echo "doing specifically"
|
||||
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
|
||||
|
||||
# simple file
|
||||
echo "doing specifically"
|
||||
echo "* test simple file"
|
||||
[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1
|
||||
grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1)
|
||||
@@ -236,6 +260,11 @@ echo "* test linked file"
|
||||
[ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1
|
||||
grep 'header' ${tmpd}/f1 || (echo "header stripped" && exit 1)
|
||||
|
||||
# normal dotfile
|
||||
echo "* normal dotfile"
|
||||
[ ! -e ${tmpd}/fn ] && echo 'not installed' && exit 1
|
||||
grep 'should not be stripped' ${tmpd}/fn && echo "no templated" && exit 1
|
||||
|
||||
## CLEANING
|
||||
rm -rf ${tmps} ${tmpd}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user