1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 15:39:43 +00:00

fix compare bug

This commit is contained in:
deadc0de6
2020-09-04 07:10:41 +02:00
parent 6565a76b1e
commit 69cf14e302
5 changed files with 24 additions and 13 deletions

View File

@@ -135,8 +135,9 @@ class CfgAggregator:
objects.append(o)
if not islist:
objects = objects[0]
if self.debug:
self.log.dbg('patching {}.{} with {}'.format(c, keys, objects))
# if self.debug:
# er = 'patching {}.{} with {}'
# self.log.dbg(er.format(c, keys, objects))
setattr(c, keys, objects)
def del_dotfile(self, dotfile):

View File

@@ -230,6 +230,7 @@ def cmd_compare(o, tmp):
newvars = dotfile.get_dotfile_variables()
t.add_tmp_vars(newvars=newvars)
# dotfiles does not exist / not installed
if o.debug:
LOG.dbg('comparing {}'.format(dotfile))
src = dotfile.src
@@ -239,9 +240,9 @@ def cmd_compare(o, tmp):
same = False
continue
# apply transformation
tmpsrc = None
if dotfile.trans_r:
# apply transformation
if o.debug:
LOG.dbg('applying transformation before comparing')
tmpsrc = apply_trans(o.dotpath, dotfile, t, debug=o.debug)
@@ -261,20 +262,26 @@ def cmd_compare(o, tmp):
LOG.dbg('points to itself')
continue
# install dotfile to temporary dir
ret, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst)
# install dotfile to temporary dir and compare
ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst)
if not ret:
# failed to install to tmp
line = '=> compare {}: error'
LOG.log(line.format(dotfile.key, err))
LOG.err(err)
same = False
continue
ignores = list(set(o.compare_ignore + dotfile.cmpignore))
ignores = patch_ignores(ignores, dotfile.dst, debug=o.debug)
diff = comp.compare(insttmp, dotfile.dst, ignore=ignores)
# clean tmp transformed dotfile if any
if tmpsrc:
# clean tmp transformed dotfile if any
tmpsrc = os.path.join(o.dotpath, tmpsrc)
if os.path.exists(tmpsrc):
remove(tmpsrc)
# print diff result
if diff == '':
if o.debug:
line = '=> compare {}: diffing with \"{}\"'

View File

@@ -551,9 +551,10 @@ class Installer:
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
if self.debug:
self.log.dbg('tmp install {} to {}'.format(src, dst))
self.log.dbg('tmp install {} (defined dst: {})'.format(src, dst))
# install the dotfile to a temp directory for comparing
ret, tmpdst = self._install_to_temp(templater, src, dst, tmpdir)
r, tmpdst = self._install_to_temp(templater, src, dst, tmpdir)
ret, err = r
if self.debug:
self.log.dbg('tmp installed in {}'.format(tmpdst))
# reset flags
@@ -561,4 +562,4 @@ class Installer:
self.diff = diffsaved
self.comparing = False
self.create = createsaved
return ret, tmpdst
return ret, err, tmpdst

View File

@@ -90,7 +90,8 @@ class Templategen:
try:
return self._handle_file(src)
except UndefinedError as e:
raise UndefinedException(e.message)
err = 'undefined variable: {}'.format(e.message)
raise UndefinedException(err)
def generate_string(self, string):
"""
@@ -103,7 +104,8 @@ class Templategen:
try:
return self.env.from_string(string).render(self.variables)
except UndefinedError as e:
raise UndefinedException(e.message)
err = 'undefined variable: {}'.format(e.message)
raise UndefinedException(err)
def add_tmp_vars(self, newvars={}):
"""add vars to the globals, make sure to call restore_vars"""

View File

@@ -36,8 +36,8 @@ class TestCompare(unittest.TestCase):
results = {}
for dotfile in dotfiles:
path = os.path.expanduser(dotfile.dst)
ret, insttmp = inst.install_to_temp(t, tmp, dotfile.src,
dotfile.dst)
ret, err, insttmp = inst.install_to_temp(t, tmp, dotfile.src,
dotfile.dst)
if not ret:
results[path] = False
continue