From ddbcbafeacf8c712c00fc822acd4300ebcbf5513 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Thu, 28 Dec 2017 17:58:13 +0100 Subject: [PATCH] adding ability to pass arguments to diff --- dotdrop/config.py | 6 +++--- dotdrop/dotdrop.py | 8 ++++++-- dotdrop/installer.py | 5 +++-- dotdrop/utils.py | 6 ++++-- tests/helpers.py | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dotdrop/config.py b/dotdrop/config.py index 4e8fa72..88ed2b5 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -195,9 +195,9 @@ class Cfg: self.prodots[profile] = [] self.prodots[profile].append(dotfile) - l = self.content[self.key_profiles][profile] - if self.key_all not in l[self.key_profiles_dots]: - l[self.key_profiles_dots].append(dotfile.key) + ent = self.content[self.key_profiles][profile] + if self.key_all not in ent[self.key_profiles_dots]: + ent[self.key_profiles_dots].append(dotfile.key) return True # adding the dotfile diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 5277c21..cc62ed9 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -56,8 +56,9 @@ USAGE = """ Usage: dotdrop install [-fndV] [-c ] [-p ] - dotdrop compare [-V] [-c ] [-p ] [--files=] dotdrop import [-ldV] [-c ] [-p ] ... + dotdrop compare [-V] [-c ] [-p ] + [-o ] [--files=] dotdrop listfiles [-V] [-c ] [-p ] dotdrop list [-V] [-c ] dotdrop --help @@ -67,6 +68,7 @@ Options: -p --profile= Specify the profile to use [default: %s]. -c --cfg= Path to the config [default: config.yaml]. --files= Comma separated list of files to compare. + -o --dopts= Diff options [default: ]. -n --nodiff Do not diff when installing. -l --link Import and link. -f --force Do not warn if exists. @@ -131,7 +133,8 @@ def compare(opts, conf, tmp, focus=None): for dotfile in selected: same, diff = inst.compare(t, tmp, opts['profile'], - dotfile.src, dotfile.dst) + dotfile.src, dotfile.dst, + opts=opts['dopts']) if same: if not opts['quiet']: LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, @@ -256,6 +259,7 @@ def main(): elif args['compare']: # compare local dotfiles with dotfiles stored in dotdrop tmp = get_tmpdir() + opts['dopts'] = args['--dopts'] if compare(opts, conf, tmp, args['--files']): LOG.raw('\ntemporary files available under %s' % (tmp)) else: diff --git a/dotdrop/installer.py b/dotdrop/installer.py index ff5d0b5..dce7f91 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -157,7 +157,7 @@ class Installer: tmpdst = os.path.join(tmpfolder, sub) return self.install(templater, profile, src, tmpdst), tmpdst - def compare(self, templater, tmpfolder, profile, src, dst): + def compare(self, templater, tmpfolder, profile, src, dst, opts=''): '''Compare temporary generated dotfile with local one''' self.comparing = True retval = False, '' @@ -175,7 +175,8 @@ class Installer: src, dst, tmpfolder) if ret: - diff = utils.diff(tmpdst, dst, log=False, raw=False) + diff = utils.diff(tmpdst, dst, log=False, + raw=False, opts=opts) if diff == '': retval = True, '' else: diff --git a/dotdrop/utils.py b/dotdrop/utils.py index afd46aa..45765d5 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -7,6 +7,7 @@ utilities import subprocess import tempfile import os +import shlex from shutil import rmtree # local import @@ -28,8 +29,9 @@ def run(cmd, log=False, raw=True): return ''.join(lines) -def diff(src, dst, log=False, raw=True): - return run(['diff', '-r', src, dst], log=log, raw=raw) +def diff(src, dst, log=False, raw=True, opts=''): + cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst) + return run(shlex.split(cmd), log=log, raw=raw) def get_tmpdir(): diff --git a/tests/helpers.py b/tests/helpers.py index 77f549b..69b737c 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -72,6 +72,7 @@ def load_config(confpath, profile): opts['installdiff'] = True opts['link'] = False opts['quiet'] = True + opts['dopts'] = '' return conf, opts