1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-11 22:24:01 +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) objects.append(o)
if not islist: if not islist:
objects = objects[0] objects = objects[0]
if self.debug: # if self.debug:
self.log.dbg('patching {}.{} with {}'.format(c, keys, objects)) # er = 'patching {}.{} with {}'
# self.log.dbg(er.format(c, keys, objects))
setattr(c, keys, objects) setattr(c, keys, objects)
def del_dotfile(self, dotfile): def del_dotfile(self, dotfile):

View File

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

View File

@@ -551,9 +551,10 @@ class Installer:
src = os.path.expanduser(src) src = os.path.expanduser(src)
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
if self.debug: 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 # 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: if self.debug:
self.log.dbg('tmp installed in {}'.format(tmpdst)) self.log.dbg('tmp installed in {}'.format(tmpdst))
# reset flags # reset flags
@@ -561,4 +562,4 @@ class Installer:
self.diff = diffsaved self.diff = diffsaved
self.comparing = False self.comparing = False
self.create = createsaved self.create = createsaved
return ret, tmpdst return ret, err, tmpdst

View File

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

View File

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