From 87f32478d90297efbc8e7e4e580fcc5143e5b1cf Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 15 Nov 2020 17:49:57 +0100 Subject: [PATCH] add more logs --- dotdrop/dotdrop.py | 15 ++++++++++++++- dotdrop/updater.py | 6 ++++-- tests-ng/diff-cmd.sh | 6 +++--- tests-ng/global-update-ignore.sh | 5 +++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index bb9f410..bce26ae 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -254,6 +254,7 @@ def cmd_install(o): def cmd_compare(o, tmp): """compare dotfiles and return True if all identical""" + cnt = 0 dotfiles = o.dotfiles if not dotfiles: msg = 'no dotfile defined for this profile (\"{}\")' @@ -266,6 +267,7 @@ def cmd_compare(o, tmp): selected = _select(o.compare_focus, dotfiles) if len(selected) < 1: + LOG.log('\nno dotfile to compare') return False t = _get_templater(o) @@ -281,6 +283,8 @@ def cmd_compare(o, tmp): if not dotfile.src and not dotfile.dst: # ignore fake dotfile continue + cnt += 1 + # add dotfile variables t.restore_vars(tvars) newvars = dotfile.get_dotfile_variables() @@ -355,12 +359,14 @@ def cmd_compare(o, tmp): LOG.emph(diff) same = False + LOG.log('\n{} dotfile(s) compared.'.format(cnt)) return same def cmd_update(o): """update the dotfile(s) from path(s) or key(s)""" ret = True + cnt = 0 paths = o.update_path iskey = o.update_iskey ignore = o.update_ignore @@ -374,10 +380,11 @@ def cmd_update(o): paths = [d.dst for d in o.dotfiles] msg = 'Update all dotfiles for profile \"{}\"'.format(o.profile) if o.safe and not LOG.ask(msg): + LOG.log('\n{} file(s) updated.'.format(cnt)) return False if not paths: - LOG.log('no dotfile to update') + LOG.log('\nno dotfile to update') return True if o.debug: LOG.dbg('dotfile to update: {}'.format(paths)) @@ -385,6 +392,7 @@ def cmd_update(o): updater = Updater(o.dotpath, o.variables, o.conf, dry=o.dry, safe=o.safe, debug=o.debug, ignore=ignore, showpatch=showpatch) + cnt = 0 if not iskey: # update paths if o.debug: @@ -392,6 +400,8 @@ def cmd_update(o): for path in paths: if not updater.update_path(path): ret = False + else: + cnt += 1 else: # update keys keys = paths @@ -403,6 +413,9 @@ def cmd_update(o): for key in keys: if not updater.update_key(key): ret = False + else: + cnt += 1 + LOG.log('\n{} file(s) updated.'.format(cnt)) return ret diff --git a/dotdrop/updater.py b/dotdrop/updater.py index e6cbf3c..15c8830 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -180,9 +180,11 @@ class Updater: return False def _mirror_rights(self, src, dst): + srcr = get_file_perm(src) + dstr = get_file_perm(dst) + if srcr == dstr: + return if self.debug: - srcr = get_file_perm(src) - dstr = get_file_perm(dst) msg = 'copy rights from {} ({:o}) to {} ({:o})' self.log.dbg(msg.format(src, srcr, dst, dstr)) try: diff --git a/tests-ng/diff-cmd.sh b/tests-ng/diff-cmd.sh index 166135d..f44e11f 100755 --- a/tests-ng/diff-cmd.sh +++ b/tests-ng/diff-cmd.sh @@ -81,7 +81,7 @@ echo "modified" > ${tmpd}/singlefile # default diff (unified) echo "[+] comparing with default diff (unified)" set +e -cd ${ddpath} | ${bin} compare -c ${cfg} 2>&1 | grep -v '=>' | grep -v '^+++\|^---' > ${tmpd}/normal +cd ${ddpath} | ${bin} compare -c ${cfg} 2>&1 | grep -v '=>' | grep -v 'dotfile(s) compared' | sed '$d' | grep -v '^+++\|^---' > ${tmpd}/normal diff -u -r ${tmpd}/singlefile ${basedir}/dotfiles/${tmpd}/singlefile | grep -v '^+++\|^---' > ${tmpd}/real set -e @@ -96,7 +96,7 @@ sed '/dotpath: dotfiles/a \ \ diff_command: "diff -r {0} {1}"' ${cfg} > ${cfg2} # normal diff echo "[+] comparing with normal diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg2} 2>&1 | grep -v '=>' > ${tmpd}/unified +cd ${ddpath} | ${bin} compare -c ${cfg2} 2>&1 | grep -v '=>' | grep -v 'dotfile(s) compared' | sed '$d' > ${tmpd}/unified diff -r ${tmpd}/singlefile ${basedir}/dotfiles/${tmpd}/singlefile > ${tmpd}/real set -e @@ -113,7 +113,7 @@ sed '/dotpath: dotfiles/a \ \ diff_command: "echo fakediff"' ${cfg} > ${cfg3} # fake diff echo "[+] comparing with fake diff" set +e -cd ${ddpath} | ${bin} compare -c ${cfg3} 2>&1 | grep -v '=>' > ${tmpd}/fake +cd ${ddpath} | ${bin} compare -c ${cfg3} 2>&1 | grep -v '=>' | grep -v 'dotfile(s) compared' | sed '$d' > ${tmpd}/fake set -e # verify diff --git a/tests-ng/global-update-ignore.sh b/tests-ng/global-update-ignore.sh index 5b4c302..93c6971 100755 --- a/tests-ng/global-update-ignore.sh +++ b/tests-ng/global-update-ignore.sh @@ -99,8 +99,9 @@ cd ${ddpath} | ${bin} update -f -c ${cfg} --verbose --profile=p1 --key f_abc # check files haven't been updated [ ! -e ${dt}/a/c/acfile ] && echo "acfile not found" && exit 1 -cat ${dt}/a/c/acfile -grep 'b' ${dt}/a/c/acfile >/dev/null +set +e +grep 'b' ${dt}/a/c/acfile || (echo "acfile not updated" && exit 1) +set -e [ -e ${dt}/a/newfile ] && echo "newfile found" && exit 1 ## CLEANING