1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-10 14:29:15 +00:00

fix tests

This commit is contained in:
deadc0de6
2020-10-09 21:02:07 +02:00
parent 4a74e71bb7
commit 971c76d95d
6 changed files with 73 additions and 44 deletions

View File

@@ -58,7 +58,7 @@ class CfgYaml:
key_dotfile_actions = 'actions' key_dotfile_actions = 'actions'
key_dotfile_link_children = 'link_children' key_dotfile_link_children = 'link_children'
key_dotfile_noempty = 'ignoreempty' key_dotfile_noempty = 'ignoreempty'
key_dotfile_notemplate = 'notemplate' key_dotfile_template = 'template'
# profile # profile
key_profile_dotfiles = 'dotfiles' key_profile_dotfiles = 'dotfiles'
@@ -84,7 +84,7 @@ class CfgYaml:
key_settings_noempty = Settings.key_ignoreempty key_settings_noempty = Settings.key_ignoreempty
key_settings_minversion = Settings.key_minversion key_settings_minversion = Settings.key_minversion
key_imp_link = Settings.key_link_on_import 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 # link values
lnk_nolink = LinkTypes.NOLINK.name.lower() lnk_nolink = LinkTypes.NOLINK.name.lower()
@@ -599,10 +599,10 @@ class CfgYaml:
if self.key_dotfile_noempty not in v: if self.key_dotfile_noempty not in v:
val = self.settings.get(self.key_settings_noempty, False) val = self.settings.get(self.key_settings_noempty, False)
v[self.key_dotfile_noempty] = val v[self.key_dotfile_noempty] = val
# apply notemplate if undefined # apply template if undefined
if self.key_dotfile_notemplate not in v: if self.key_dotfile_template not in v:
val = self.settings.get(self.key_settings_notemplate, False) val = self.settings.get(self.key_settings_template, True)
v[self.key_dotfile_notemplate] = val v[self.key_dotfile_template] = val
return new return new

View File

@@ -130,12 +130,12 @@ def cmd_install(o):
if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK: if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.LINK:
r, err = inst.link(t, dotfile.src, dotfile.dst, r, err = inst.link(t, dotfile.src, dotfile.dst,
actionexec=pre_actions_exec, actionexec=pre_actions_exec,
notemplate=dotfile.notemplate) template=dotfile.template)
elif hasattr(dotfile, 'link') and \ elif hasattr(dotfile, 'link') and \
dotfile.link == LinkTypes.LINK_CHILDREN: dotfile.link == LinkTypes.LINK_CHILDREN:
r, err = inst.link_children(t, dotfile.src, dotfile.dst, r, err = inst.link_children(t, dotfile.src, dotfile.dst,
actionexec=pre_actions_exec, actionexec=pre_actions_exec,
notemplate=dotfile.notemplate) template=dotfile.template)
else: else:
src = dotfile.src src = dotfile.src
tmp = None tmp = None
@@ -150,7 +150,7 @@ def cmd_install(o):
actionexec=pre_actions_exec, actionexec=pre_actions_exec,
noempty=dotfile.noempty, noempty=dotfile.noempty,
ignore=ignores, ignore=ignores,
notemplate=dotfile.notemplate) template=dotfile.template)
if tmp: if tmp:
tmp = os.path.join(o.dotpath, tmp) tmp = os.path.join(o.dotpath, tmp)
if os.path.exists(tmp): if os.path.exists(tmp):
@@ -268,7 +268,7 @@ def cmd_compare(o, tmp):
# install dotfile to temporary dir and compare # install dotfile to temporary dir and compare
ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst, ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst,
notemplate=dotfile.notemplate) template=dotfile.template)
if not ret: if not ret:
# failed to install to tmp # failed to install to tmp
line = '=> compare {}: error' line = '=> compare {}: error'

View File

@@ -16,13 +16,13 @@ class Dotfile(DictParser):
key_noempty = 'ignoreempty' key_noempty = 'ignoreempty'
key_trans_r = 'trans_read' key_trans_r = 'trans_read'
key_trans_w = 'trans_write' key_trans_w = 'trans_write'
key_notemplate = 'notemplate' key_template = 'template'
def __init__(self, key, dst, src, def __init__(self, key, dst, src,
actions=[], trans_r=None, trans_w=None, actions=[], trans_r=None, trans_w=None,
link=LinkTypes.NOLINK, noempty=False, link=LinkTypes.NOLINK, noempty=False,
cmpignore=[], upignore=[], cmpignore=[], upignore=[],
instignore=[], notemplate=False): instignore=[], template=True):
""" """
constructor constructor
@key: dotfile key @key: dotfile key
@@ -36,7 +36,7 @@ class Dotfile(DictParser):
@upignore: patterns to ignore when updating @upignore: patterns to ignore when updating
@cmpignore: patterns to ignore when comparing @cmpignore: patterns to ignore when comparing
@instignore: patterns to ignore when installing @instignore: patterns to ignore when installing
@notemplate: disable template for this dotfile @template: template this dotfile
""" """
self.actions = actions self.actions = actions
self.dst = dst self.dst = dst
@@ -49,7 +49,7 @@ class Dotfile(DictParser):
self.upignore = upignore self.upignore = upignore
self.cmpignore = cmpignore self.cmpignore = cmpignore
self.instignore = instignore self.instignore = instignore
self.notemplate = notemplate self.template = template
if self.link != LinkTypes.NOLINK and \ if self.link != LinkTypes.NOLINK and \
( (
@@ -94,7 +94,7 @@ class Dotfile(DictParser):
value['noempty'] = value.get(cls.key_noempty, False) value['noempty'] = value.get(cls.key_noempty, False)
value['trans_r'] = value.get(cls.key_trans_r) value['trans_r'] = value.get(cls.key_trans_r)
value['trans_w'] = value.get(cls.key_trans_w) 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 # remove old entries
value.pop(cls.key_noempty, None) value.pop(cls.key_noempty, None)
value.pop(cls.key_trans_r, None) value.pop(cls.key_trans_r, None)
@@ -112,7 +112,7 @@ class Dotfile(DictParser):
msg += ', src:\"{}\"'.format(self.src) msg += ', src:\"{}\"'.format(self.src)
msg += ', dst:\"{}\"'.format(self.dst) msg += ', dst:\"{}\"'.format(self.dst)
msg += ', link:\"{}\"'.format(str(self.link)) msg += ', link:\"{}\"'.format(str(self.link))
msg += ', template:{}'.format(not self.notemplate) msg += ', template:{}'.format(self.template)
return msg return msg
def prt(self): def prt(self):
@@ -122,7 +122,7 @@ class Dotfile(DictParser):
out += '\n{}src: \"{}\"'.format(indent, self.src) out += '\n{}src: \"{}\"'.format(indent, self.src)
out += '\n{}dst: \"{}\"'.format(indent, self.dst) out += '\n{}dst: \"{}\"'.format(indent, self.dst)
out += '\n{}link: \"{}\"'.format(indent, str(self.link)) 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) out += '\n{}pre-action:'.format(indent)
some = self.get_pre_actions() some = self.get_pre_actions()

View File

@@ -66,7 +66,7 @@ class Installer:
def install(self, templater, src, dst, def install(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], notemplate=False): ignore=[], template=True):
""" """
install src to dst using a template install src to dst using a template
@templater: the templater object @templater: the templater object
@@ -75,7 +75,7 @@ class Installer:
@actionexec: action executor callback @actionexec: action executor callback
@noempty: render empty template flag @noempty: render empty template flag
@ignore: pattern to ignore when installing @ignore: pattern to ignore when installing
@notemplate: do not template @template: template this dotfile
return return
- True, None : success - True, None : success
@@ -108,22 +108,22 @@ class Installer:
b, e = self._install_dir(templater, src, dst, b, e = self._install_dir(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, ignore=ignore, noempty=noempty, ignore=ignore,
notemplate=notemplate) template=template)
return self._log_install(b, e) return self._log_install(b, e)
b, e = self._install_file(templater, src, dst, b, e = self._install_file(templater, src, dst,
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, ignore=ignore, noempty=noempty, ignore=ignore,
notemplate=notemplate) template=template)
return self._log_install(b, e) 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 set src as the link target of dst
@templater: the templater @templater: the templater
@src: dotfile source path in dotpath @src: dotfile source path in dotpath
@dst: dotfile destination path in the FS @dst: dotfile destination path in the FS
@actionexec: action executor callback @actionexec: action executor callback
@notemplate: do no template @template: template this dotfile
return return
- True, None : success - True, None : success
@@ -146,16 +146,16 @@ class Installer:
if self.totemp: if self.totemp:
# ignore actions # ignore actions
b, e = self.install(templater, src, dst, actionexec=None, b, e = self.install(templater, src, dst, actionexec=None,
notemplate=notemplate) template=template)
return self._log_install(b, e) return self._log_install(b, e)
if not notemplate and Templategen.is_template(src): if template and Templategen.is_template(src):
if self.debug: if self.debug:
self.log.dbg('dotfile is a template') self.log.dbg('dotfile is a template')
self.log.dbg('install to {} and symlink'.format(self.workdir)) self.log.dbg('install to {} and symlink'.format(self.workdir))
tmp = self._pivot_path(dst, self.workdir, striphome=True) tmp = self._pivot_path(dst, self.workdir, striphome=True)
i, err = self.install(templater, src, tmp, actionexec=actionexec, i, err = self.install(templater, src, tmp, actionexec=actionexec,
notemplate=notemplate) template=template)
if not i and not os.path.exists(tmp): if not i and not os.path.exists(tmp):
return self._log_install(i, err) return self._log_install(i, err)
src = tmp src = tmp
@@ -163,14 +163,14 @@ class Installer:
return self._log_install(b, e) return self._log_install(b, e)
def link_children(self, templater, src, dst, actionexec=None, def link_children(self, templater, src, dst, actionexec=None,
notemplate=False): template=True):
""" """
link all dotfiles in a given directory link all dotfiles in a given directory
@templater: the templater @templater: the templater
@src: dotfile source path in dotpath @src: dotfile source path in dotpath
@dst: dotfile destination path in the FS @dst: dotfile destination path in the FS
@actionexec: action executor callback @actionexec: action executor callback
@notemplate: do not template @template: template this dotfile
return return
- True, None: success - True, None: success
@@ -230,14 +230,14 @@ class Installer:
if self.debug: if self.debug:
self.log.dbg('symlink child {} to {}'.format(src, dst)) 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: if self.debug:
self.log.dbg('dotfile is a template') self.log.dbg('dotfile is a template')
self.log.dbg('install to {} and symlink' self.log.dbg('install to {} and symlink'
.format(self.workdir)) .format(self.workdir))
tmp = self._pivot_path(dst, self.workdir, striphome=True) tmp = self._pivot_path(dst, self.workdir, striphome=True)
r, e = self.install(templater, src, tmp, actionexec=actionexec, r, e = self.install(templater, src, tmp, actionexec=actionexec,
notemplate=notemplate) template=template)
if not r and e and not os.path.exists(tmp): if not r and e and not os.path.exists(tmp):
continue continue
src = tmp src = tmp
@@ -318,13 +318,13 @@ class Installer:
def _install_file(self, templater, src, dst, def _install_file(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], notemplate=False): ignore=[], template=True):
"""install src to dst when is a file""" """install src to dst when is a file"""
if self.debug: if self.debug:
self.log.dbg('deploy file: {}'.format(src)) self.log.dbg('deploy file: {}'.format(src))
self.log.dbg('ignore empty: {}'.format(noempty)) self.log.dbg('ignore empty: {}'.format(noempty))
self.log.dbg('ignore pattern: {}'.format(ignore)) 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)) self.log.dbg('no empty: {}'.format(noempty))
if utils.must_ignore([src, dst], ignore, debug=self.debug): if utils.must_ignore([src, dst], ignore, debug=self.debug):
@@ -338,7 +338,7 @@ class Installer:
return False, err return False, err
# handle the file # handle the file
if not notemplate: if template:
# template the file # template the file
saved = templater.add_tmp_vars(self._get_tmp_file_vars(src, dst)) saved = templater.add_tmp_vars(self._get_tmp_file_vars(src, dst))
try: try:
@@ -389,7 +389,7 @@ class Installer:
def _install_dir(self, templater, src, dst, def _install_dir(self, templater, src, dst,
actionexec=None, noempty=False, actionexec=None, noempty=False,
ignore=[], notemplate=False): ignore=[], template=True):
"""install src to dst when is a directory""" """install src to dst when is a directory"""
if self.debug: if self.debug:
self.log.dbg('install dir {}'.format(src)) self.log.dbg('install dir {}'.format(src))
@@ -409,7 +409,7 @@ class Installer:
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
notemplate=notemplate) template=template)
if not res and err: if not res and err:
# error occured # error occured
ret = res, err ret = res, err
@@ -424,7 +424,7 @@ class Installer:
actionexec=actionexec, actionexec=actionexec,
noempty=noempty, noempty=noempty,
ignore=ignore, ignore=ignore,
notemplate=notemplate) template=template)
if not res and err: if not res and err:
# error occured # error occured
ret = res, err ret = res, err
@@ -562,13 +562,13 @@ class Installer:
self.action_executed = True self.action_executed = True
return ret, err 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""" """install a dotfile to a tempdir"""
tmpdst = self._pivot_path(dst, tmpdir) 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 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""" """install a dotfile to a tempdir"""
ret = False ret = False
tmpdst = '' tmpdst = ''
@@ -587,7 +587,7 @@ class Installer:
self.log.dbg('tmp install {} (defined dst: {})'.format(src, dst)) self.log.dbg('tmp install {} (defined dst: {})'.format(src, dst))
# install the dotfile to a temp directory for comparing # install the dotfile to a temp directory for comparing
r, tmpdst = self._install_to_temp(templater, src, dst, tmpdir, r, tmpdst = self._install_to_temp(templater, src, dst, tmpdir,
notemplate=notemplate) template=template)
ret, err = r ret, err = r
if self.debug: if self.debug:
self.log.dbg('tmp installed in {}'.format(tmpdst)) self.log.dbg('tmp installed in {}'.format(tmpdst))

View File

@@ -51,7 +51,7 @@ class Settings(DictParser):
workdir='~/.config/dotdrop', showdiff=False, workdir='~/.config/dotdrop', showdiff=False,
minversion=None, func_file=[], filter_file=[], minversion=None, func_file=[], filter_file=[],
diff_command='diff -r -u {0} {1}', diff_command='diff -r -u {0} {1}',
template_dotfile_default=False): template_dotfile_default=True):
self.backup = backup self.backup = backup
self.banner = banner self.banner = banner
self.create = create self.create = create

View File

@@ -63,7 +63,7 @@ config:
backup: true backup: true
create: true create: true
dotpath: dotfiles dotpath: dotfiles
template_dotfile_default: true template_dotfile_default: false
dotfiles: dotfiles:
f_f1: f_f1:
dst: ${tmpd}/f1 dst: ${tmpd}/f1
@@ -83,6 +83,10 @@ dotfiles:
dst: ${tmpd}/fl dst: ${tmpd}/fl
src: fl src: fl
link: link link: link
f_fn:
dst: ${tmpd}/fn
src: fn
template: true
profiles: profiles:
p1: p1:
dotfiles: dotfiles:
@@ -91,6 +95,7 @@ profiles:
- d_d2 - d_d2
- d_d3 - d_d3
- f_fl - f_fl
- f_fn
_EOF _EOF
#cat ${cfg} #cat ${cfg}
@@ -116,11 +121,16 @@ echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/dir3/s2/f2
# create the linked dotfile # create the linked dotfile
echo "{{@@ header() @@}}" >> ${tmps}/dotfiles/fl 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 # install
echo "doing globally"
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
# simple file # simple file
echo "doing globally"
echo "* test simple file" echo "* test simple file"
[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1 [ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1
grep 'header' ${tmpd}/f1 || (echo "header stripped" && 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 [ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1
grep 'header' ${tmpd}/f1 || (echo "header stripped" && 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 # through the dotfile
cat > ${cfg} << _EOF cat > ${cfg} << _EOF
config: config:
@@ -167,21 +182,29 @@ dotfiles:
f_f1: f_f1:
dst: ${tmpd}/f1 dst: ${tmpd}/f1
src: f1 src: f1
template: false
d_d1: d_d1:
dst: ${tmpd}/dir1 dst: ${tmpd}/dir1
src: dir1 src: dir1
template: false
d_d2: d_d2:
dst: ${tmpd}/dir2 dst: ${tmpd}/dir2
src: dir2 src: dir2
link: link link: link
template: false
d_d3: d_d3:
dst: ${tmpd}/dir3 dst: ${tmpd}/dir3
src: dir3 src: dir3
link: link_children link: link_children
template: false
f_fl: f_fl:
dst: ${tmpd}/fl dst: ${tmpd}/fl
src: fl src: fl
link: link link: link
template: false
f_fn:
dst: ${tmpd}/fn
src: fn
profiles: profiles:
p1: p1:
dotfiles: dotfiles:
@@ -190,6 +213,7 @@ profiles:
- d_d2 - d_d2
- d_d3 - d_d3
- f_fl - f_fl
- f_fn
_EOF _EOF
#cat ${cfg} #cat ${cfg}
@@ -197,10 +221,10 @@ _EOF
rm -rf ${tmpd}/* rm -rf ${tmpd}/*
# install # install
echo "doing specifically"
cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V cd ${ddpath} | ${bin} install -f -c ${cfg} -p p1 -V
# simple file # simple file
echo "doing specifically"
echo "* test simple file" echo "* test simple file"
[ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1 [ ! -e ${tmpd}/f1 ] && echo 'not installed1' && exit 1
grep 'header' ${tmpd}/f1 || (echo "header stripped" && 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 [ ! -h ${tmpd}/fl ] && echo 'not installed' && exit 1
grep 'header' ${tmpd}/f1 || (echo "header stripped" && 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 ## CLEANING
rm -rf ${tmps} ${tmpd} rm -rf ${tmps} ${tmpd}