diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index b06d618..b80b2d8 100755 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -30,8 +30,8 @@ USAGE = """ %s Usage: - dotdrop.py install [-fndc ] [--profile=] - dotdrop.py compare [-c ] [--profile=] [--files=] + dotdrop.py install [-fndvc ] [--profile=] + dotdrop.py compare [-vc ] [--profile=] [--files=] dotdrop.py import [-ldc ] [--profile=] ... dotdrop.py list [-c ] dotdrop.py --help @@ -44,6 +44,7 @@ Options: -n --nodiff Do not diff when installing. -l --link Import and link. -f --force Do not warn if exists. + -v --verbose Be verbose. -d --dry Dry run. --version Show version. -h --help Show this screen. @@ -64,7 +65,7 @@ def install(opts, conf): t = Templategen(base=opts['dotpath']) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], safe=opts['safe'], base=opts['dotpath'], - diff=opts['installdiff']) + diff=opts['installdiff'], quiet=opts['quiet']) installed = [] for dotfile in dotfiles: if hasattr(dotfile, "link") and dotfile.link: @@ -84,7 +85,8 @@ def compare(opts, conf, tmp, focus=None): return False t = Templategen(base=opts['dotpath']) 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 selected = dotfiles @@ -98,8 +100,17 @@ def compare(opts, conf, tmp, focus=None): LOG.err('no dotfile matches \"%s\"' % (selection)) for dotfile in selected: - LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst)) - inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst) + same, diff = inst.compare(t, tmp, opts['profile'], + 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 @@ -177,6 +188,7 @@ if __name__ == '__main__': opts['safe'] = not args['--force'] opts['installdiff'] = not args['--nodiff'] opts['link'] = args['--link'] + opts['quiet'] = not args['--verbose'] header() @@ -191,7 +203,7 @@ if __name__ == '__main__': elif args['compare']: tmp = utils.get_tmpdir() 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: os.rmdir(tmp) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index d623f95..d2d976d 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -22,6 +22,7 @@ class Installer: self.base = base self.quiet = quiet self.diff = diff + self.comparing = False self.log = Logger() def install(self, templater, profile, src, dst): @@ -76,10 +77,11 @@ class Installer: self.log.err('installing %s to %s' % (src, dst)) return [] if ret > 0: - self.log.sub('ignoring \"%s\", same content' % (dst)) + if not self.quiet: + self.log.sub('ignoring \"%s\", same content' % (dst)) return [] 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)) return [(src, dst)] return [] @@ -155,6 +157,7 @@ class Installer: def compare(self, templater, tmpfolder, profile, src, dst): '''Compare temporary generated dotfile with local one''' + self.comparing = True retval = False drysaved = self.dry self.dry = False @@ -172,10 +175,10 @@ class Installer: if ret: diff = utils.diff(tmpdst, dst, log=False, raw=False) if diff == '': - self.log.raw('same file') - retval = True + retval = True, '' else: - self.log.emph(diff) + retval = False, diff self.dry = drysaved self.diff = diffsaved + self.comparing = False return retval diff --git a/tests/test_compare.py b/tests/test_compare.py index 9b22e6b..5091fc9 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -33,10 +33,10 @@ class TestCompare(unittest.TestCase): dry=opts['dry'], base=opts['dotpath'], quiet=True) results = {} for dotfile in dotfiles: - diffval = inst.compare(t, tmp, opts['profile'], + same, _ = inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst) path = os.path.expanduser(dotfile.dst) - results[path] = diffval + results[path] = same return results def edit_content(self, path, newcontent, binary=False): diff --git a/tests/test_install.py b/tests/test_install.py index 13e8887..0fffccd 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -124,6 +124,7 @@ exec bspwm # install them conf, opts = load_config(confpath, profile) opts['safe'] = False + opts['quiet'] = True install(opts, conf) # now compare the generated files