1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-08 14:19:16 +00:00

adding ability to pass arguments to diff

This commit is contained in:
deadc0de6
2017-12-28 17:58:13 +01:00
parent e2cc16bee9
commit ddbcbafeac
5 changed files with 17 additions and 9 deletions

View File

@@ -195,9 +195,9 @@ class Cfg:
self.prodots[profile] = [] self.prodots[profile] = []
self.prodots[profile].append(dotfile) self.prodots[profile].append(dotfile)
l = self.content[self.key_profiles][profile] ent = self.content[self.key_profiles][profile]
if self.key_all not in l[self.key_profiles_dots]: if self.key_all not in ent[self.key_profiles_dots]:
l[self.key_profiles_dots].append(dotfile.key) ent[self.key_profiles_dots].append(dotfile.key)
return True return True
# adding the dotfile # adding the dotfile

View File

@@ -56,8 +56,9 @@ USAGE = """
Usage: Usage:
dotdrop install [-fndV] [-c <path>] [-p <profile>] dotdrop install [-fndV] [-c <path>] [-p <profile>]
dotdrop compare [-V] [-c <path>] [-p <profile>] [--files=<files>]
dotdrop import [-ldV] [-c <path>] [-p <profile>] <paths>... dotdrop import [-ldV] [-c <path>] [-p <profile>] <paths>...
dotdrop compare [-V] [-c <path>] [-p <profile>]
[-o <opts>] [--files=<files>]
dotdrop listfiles [-V] [-c <path>] [-p <profile>] dotdrop listfiles [-V] [-c <path>] [-p <profile>]
dotdrop list [-V] [-c <path>] dotdrop list [-V] [-c <path>]
dotdrop --help dotdrop --help
@@ -67,6 +68,7 @@ Options:
-p --profile=<profile> Specify the profile to use [default: %s]. -p --profile=<profile> Specify the profile to use [default: %s].
-c --cfg=<path> Path to the config [default: config.yaml]. -c --cfg=<path> Path to the config [default: config.yaml].
--files=<files> Comma separated list of files to compare. --files=<files> Comma separated list of files to compare.
-o --dopts=<opts> Diff options [default: ].
-n --nodiff Do not diff when installing. -n --nodiff Do not diff when installing.
-l --link Import and link. -l --link Import and link.
-f --force Do not warn if exists. -f --force Do not warn if exists.
@@ -131,7 +133,8 @@ def compare(opts, conf, tmp, focus=None):
for dotfile in selected: for dotfile in selected:
same, diff = inst.compare(t, tmp, opts['profile'], same, diff = inst.compare(t, tmp, opts['profile'],
dotfile.src, dotfile.dst) dotfile.src, dotfile.dst,
opts=opts['dopts'])
if same: if same:
if not opts['quiet']: if not opts['quiet']:
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key,
@@ -256,6 +259,7 @@ def main():
elif args['compare']: elif args['compare']:
# compare local dotfiles with dotfiles stored in dotdrop # compare local dotfiles with dotfiles stored in dotdrop
tmp = get_tmpdir() tmp = get_tmpdir()
opts['dopts'] = args['--dopts']
if compare(opts, conf, tmp, args['--files']): if compare(opts, conf, tmp, args['--files']):
LOG.raw('\ntemporary files available under %s' % (tmp)) LOG.raw('\ntemporary files available under %s' % (tmp))
else: else:

View File

@@ -157,7 +157,7 @@ class Installer:
tmpdst = os.path.join(tmpfolder, sub) tmpdst = os.path.join(tmpfolder, sub)
return self.install(templater, profile, src, tmpdst), tmpdst 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''' '''Compare temporary generated dotfile with local one'''
self.comparing = True self.comparing = True
retval = False, '' retval = False, ''
@@ -175,7 +175,8 @@ class Installer:
src, dst, src, dst,
tmpfolder) tmpfolder)
if ret: if ret:
diff = utils.diff(tmpdst, dst, log=False, raw=False) diff = utils.diff(tmpdst, dst, log=False,
raw=False, opts=opts)
if diff == '': if diff == '':
retval = True, '' retval = True, ''
else: else:

View File

@@ -7,6 +7,7 @@ utilities
import subprocess import subprocess
import tempfile import tempfile
import os import os
import shlex
from shutil import rmtree from shutil import rmtree
# local import # local import
@@ -28,8 +29,9 @@ def run(cmd, log=False, raw=True):
return ''.join(lines) return ''.join(lines)
def diff(src, dst, log=False, raw=True): def diff(src, dst, log=False, raw=True, opts=''):
return run(['diff', '-r', src, dst], log=log, raw=raw) cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst)
return run(shlex.split(cmd), log=log, raw=raw)
def get_tmpdir(): def get_tmpdir():

View File

@@ -72,6 +72,7 @@ def load_config(confpath, profile):
opts['installdiff'] = True opts['installdiff'] = True
opts['link'] = False opts['link'] = False
opts['quiet'] = True opts['quiet'] = True
opts['dopts'] = ''
return conf, opts return conf, opts