From 3fc635495d669a49aa3bb76cf3699a0e9fb676e6 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 16 Nov 2020 13:50:38 +0100 Subject: [PATCH] clean run --- dotdrop/comparator.py | 2 +- dotdrop/installer.py | 2 +- dotdrop/templategen.py | 2 +- dotdrop/utils.py | 13 +++---------- tests-ng/profile-actions.sh | 3 +++ 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/dotdrop/comparator.py b/dotdrop/comparator.py index 8c28266..78c1dd4 100644 --- a/dotdrop/comparator.py +++ b/dotdrop/comparator.py @@ -143,7 +143,7 @@ class Comparator: def _diff(self, left, right, header=False): """diff two files""" - out = diff(modified=left, original=right, raw=False, + out = diff(modified=left, original=right, diff_cmd=self.diff_cmd, debug=self.debug) if header: lshort = os.path.basename(left) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 27c8004..55588fe 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -687,7 +687,7 @@ class Installer: if content: tmp = utils.write_to_tmpfile(content) src = tmp - diff = utils.diff(modified=src, original=dst, raw=False, + diff = utils.diff(modified=src, original=dst, diff_cmd=self.diff_cmd) if tmp: utils.removepath(tmp, logger=self.log) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index d5a718c..3e34622 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -153,7 +153,7 @@ class Templategen: self.log.dbg('using \"magic\" for filetype identification') except ImportError: _, filetype = utils.run(['file', '-b', '--mime-type', src], - raw=False, debug=self.debug) + debug=self.debug) if self.debug: self.log.dbg('using \"file\" for filetype identification') filetype = filetype.strip() diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 33c4a8b..b04be4b 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -33,7 +33,7 @@ DONOTDELETE = [ NOREMOVE = [os.path.normpath(p) for p in DONOTDELETE] -def run(cmd, raw=True, debug=False, checkerr=False): +def run(cmd, debug=False): """run a command (expects a list)""" if debug: LOG.dbg('exec: {}'.format(' '.join(cmd))) @@ -43,13 +43,6 @@ def run(cmd, raw=True, debug=False, checkerr=False): ret = p.returncode out = out.splitlines(keepends=True) lines = ''.join([x.decode('utf-8', 'replace') for x in out]) - if checkerr and ret != 0: - c = ' '.join(cmd) - errl = lines.rstrip() - m = '\"{}\" returned non zero ({}): {}'.format(c, ret, errl) - LOG.err(m) - if raw: - return ret == 0, out return ret == 0, lines @@ -79,7 +72,7 @@ def fastdiff(left, right): return not filecmp.cmp(left, right, shallow=False) -def diff(original, modified, raw=True, +def diff(original, modified, diff_cmd='', debug=False): """compare two files, returns '' if same""" if not diff_cmd: @@ -92,7 +85,7 @@ def diff(original, modified, raw=True, "{modified}": modified, } cmd = [replacements.get(x, x) for x in diff_cmd.split()] - _, out = run(cmd, raw=raw, debug=debug) + _, out = run(cmd, debug=debug) return out diff --git a/tests-ng/profile-actions.sh b/tests-ng/profile-actions.sh index 5840021..307f5cb 100755 --- a/tests-ng/profile-actions.sh +++ b/tests-ng/profile-actions.sh @@ -94,6 +94,9 @@ profiles: _EOF #cat ${cfg} +# list profiles +cd ${ddpath} | ${bin} profiles -c ${cfg} -V + # create the dotfile echo "test" > ${tmps}/dotfiles/abc echo "test" > ${tmps}/dotfiles/def