mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 17:24:46 +00:00
adding ability to pass arguments to diff
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -56,8 +56,9 @@ USAGE = """
|
||||
|
||||
Usage:
|
||||
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 compare [-V] [-c <path>] [-p <profile>]
|
||||
[-o <opts>] [--files=<files>]
|
||||
dotdrop listfiles [-V] [-c <path>] [-p <profile>]
|
||||
dotdrop list [-V] [-c <path>]
|
||||
dotdrop --help
|
||||
@@ -67,6 +68,7 @@ Options:
|
||||
-p --profile=<profile> Specify the profile to use [default: %s].
|
||||
-c --cfg=<path> Path to the config [default: config.yaml].
|
||||
--files=<files> Comma separated list of files to compare.
|
||||
-o --dopts=<opts> 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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -72,6 +72,7 @@ def load_config(confpath, profile):
|
||||
opts['installdiff'] = True
|
||||
opts['link'] = False
|
||||
opts['quiet'] = True
|
||||
opts['dopts'] = ''
|
||||
return conf, opts
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user