mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 16:04:00 +00:00
be verbose by default on compare and install
This commit is contained in:
@@ -30,8 +30,8 @@ USAGE = """
|
|||||||
%s
|
%s
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
dotdrop.py install [-fndc <path>] [--profile=<profile>]
|
dotdrop.py install [-fndvc <path>] [--profile=<profile>]
|
||||||
dotdrop.py compare [-c <path>] [--profile=<profile>] [--files=<files>]
|
dotdrop.py compare [-vc <path>] [--profile=<profile>] [--files=<files>]
|
||||||
dotdrop.py import [-ldc <path>] [--profile=<profile>] <paths>...
|
dotdrop.py import [-ldc <path>] [--profile=<profile>] <paths>...
|
||||||
dotdrop.py list [-c <path>]
|
dotdrop.py list [-c <path>]
|
||||||
dotdrop.py --help
|
dotdrop.py --help
|
||||||
@@ -44,6 +44,7 @@ Options:
|
|||||||
-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.
|
||||||
|
-v --verbose Be verbose.
|
||||||
-d --dry Dry run.
|
-d --dry Dry run.
|
||||||
--version Show version.
|
--version Show version.
|
||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
@@ -64,7 +65,7 @@ def install(opts, conf):
|
|||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'],
|
||||||
diff=opts['installdiff'])
|
diff=opts['installdiff'], quiet=opts['quiet'])
|
||||||
installed = []
|
installed = []
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
if hasattr(dotfile, "link") and dotfile.link:
|
if hasattr(dotfile, "link") and dotfile.link:
|
||||||
@@ -84,7 +85,8 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
return False
|
return False
|
||||||
t = Templategen(base=opts['dotpath'])
|
t = Templategen(base=opts['dotpath'])
|
||||||
inst = Installer(create=opts['create'], backup=opts['backup'],
|
inst = Installer(create=opts['create'], backup=opts['backup'],
|
||||||
dry=opts['dry'], base=opts['dotpath'], quiet=True)
|
dry=opts['dry'], base=opts['dotpath'],
|
||||||
|
quiet=opts['quiet'])
|
||||||
|
|
||||||
# compare only specific files
|
# compare only specific files
|
||||||
selected = dotfiles
|
selected = dotfiles
|
||||||
@@ -98,8 +100,17 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
LOG.err('no dotfile matches \"%s\"' % (selection))
|
LOG.err('no dotfile matches \"%s\"' % (selection))
|
||||||
|
|
||||||
for dotfile in selected:
|
for dotfile in selected:
|
||||||
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
|
same, diff = inst.compare(t, tmp, opts['profile'],
|
||||||
inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst)
|
dotfile.src, dotfile.dst)
|
||||||
|
if same:
|
||||||
|
if not opts['quiet']:
|
||||||
|
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key,
|
||||||
|
dotfile.dst))
|
||||||
|
LOG.raw('same file')
|
||||||
|
else:
|
||||||
|
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
|
||||||
|
LOG.emph(diff)
|
||||||
|
|
||||||
return len(dotfiles) > 0
|
return len(dotfiles) > 0
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +188,7 @@ if __name__ == '__main__':
|
|||||||
opts['safe'] = not args['--force']
|
opts['safe'] = not args['--force']
|
||||||
opts['installdiff'] = not args['--nodiff']
|
opts['installdiff'] = not args['--nodiff']
|
||||||
opts['link'] = args['--link']
|
opts['link'] = args['--link']
|
||||||
|
opts['quiet'] = not args['--verbose']
|
||||||
|
|
||||||
header()
|
header()
|
||||||
|
|
||||||
@@ -191,7 +203,7 @@ if __name__ == '__main__':
|
|||||||
elif args['compare']:
|
elif args['compare']:
|
||||||
tmp = utils.get_tmpdir()
|
tmp = utils.get_tmpdir()
|
||||||
if compare(opts, conf, tmp, args['--files']):
|
if compare(opts, conf, tmp, args['--files']):
|
||||||
LOG.log('generated temporary files available under %s' % (tmp))
|
LOG.raw('\ntemporary files available under %s' % (tmp))
|
||||||
else:
|
else:
|
||||||
os.rmdir(tmp)
|
os.rmdir(tmp)
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Installer:
|
|||||||
self.base = base
|
self.base = base
|
||||||
self.quiet = quiet
|
self.quiet = quiet
|
||||||
self.diff = diff
|
self.diff = diff
|
||||||
|
self.comparing = False
|
||||||
self.log = Logger()
|
self.log = Logger()
|
||||||
|
|
||||||
def install(self, templater, profile, src, dst):
|
def install(self, templater, profile, src, dst):
|
||||||
@@ -76,10 +77,11 @@ class Installer:
|
|||||||
self.log.err('installing %s to %s' % (src, dst))
|
self.log.err('installing %s to %s' % (src, dst))
|
||||||
return []
|
return []
|
||||||
if ret > 0:
|
if ret > 0:
|
||||||
self.log.sub('ignoring \"%s\", same content' % (dst))
|
if not self.quiet:
|
||||||
|
self.log.sub('ignoring \"%s\", same content' % (dst))
|
||||||
return []
|
return []
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
if not self.quiet and not self.dry:
|
if not self.quiet and not self.dry and not self.comparing:
|
||||||
self.log.sub('copied %s to %s' % (src, dst))
|
self.log.sub('copied %s to %s' % (src, dst))
|
||||||
return [(src, dst)]
|
return [(src, dst)]
|
||||||
return []
|
return []
|
||||||
@@ -155,6 +157,7 @@ class Installer:
|
|||||||
|
|
||||||
def compare(self, templater, tmpfolder, profile, src, dst):
|
def compare(self, templater, tmpfolder, profile, src, dst):
|
||||||
'''Compare temporary generated dotfile with local one'''
|
'''Compare temporary generated dotfile with local one'''
|
||||||
|
self.comparing = True
|
||||||
retval = False
|
retval = False
|
||||||
drysaved = self.dry
|
drysaved = self.dry
|
||||||
self.dry = False
|
self.dry = False
|
||||||
@@ -172,10 +175,10 @@ class Installer:
|
|||||||
if ret:
|
if ret:
|
||||||
diff = utils.diff(tmpdst, dst, log=False, raw=False)
|
diff = utils.diff(tmpdst, dst, log=False, raw=False)
|
||||||
if diff == '':
|
if diff == '':
|
||||||
self.log.raw('same file')
|
retval = True, ''
|
||||||
retval = True
|
|
||||||
else:
|
else:
|
||||||
self.log.emph(diff)
|
retval = False, diff
|
||||||
self.dry = drysaved
|
self.dry = drysaved
|
||||||
self.diff = diffsaved
|
self.diff = diffsaved
|
||||||
|
self.comparing = False
|
||||||
return retval
|
return retval
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ class TestCompare(unittest.TestCase):
|
|||||||
dry=opts['dry'], base=opts['dotpath'], quiet=True)
|
dry=opts['dry'], base=opts['dotpath'], quiet=True)
|
||||||
results = {}
|
results = {}
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
diffval = inst.compare(t, tmp, opts['profile'],
|
same, _ = inst.compare(t, tmp, opts['profile'],
|
||||||
dotfile.src, dotfile.dst)
|
dotfile.src, dotfile.dst)
|
||||||
path = os.path.expanduser(dotfile.dst)
|
path = os.path.expanduser(dotfile.dst)
|
||||||
results[path] = diffval
|
results[path] = same
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def edit_content(self, path, newcontent, binary=False):
|
def edit_content(self, path, newcontent, binary=False):
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ exec bspwm
|
|||||||
# install them
|
# install them
|
||||||
conf, opts = load_config(confpath, profile)
|
conf, opts = load_config(confpath, profile)
|
||||||
opts['safe'] = False
|
opts['safe'] = False
|
||||||
|
opts['quiet'] = True
|
||||||
install(opts, conf)
|
install(opts, conf)
|
||||||
|
|
||||||
# now compare the generated files
|
# now compare the generated files
|
||||||
|
|||||||
Reference in New Issue
Block a user