From 881537443bdd795a0e5074b7b75087fc7d1abe59 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 2 May 2018 20:29:36 +0200 Subject: [PATCH] rename quiet as debug --- dotdrop/dotdrop.py | 19 +++++++++++-------- dotdrop/installer.py | 12 +++++------- dotdrop/logger.py | 9 +++++++-- dotdrop/utils.py | 13 ++++--------- tests/helpers.py | 2 +- tests/test_compare.py | 2 +- tests/test_install.py | 2 +- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index c06ec74..55ccdbc 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -83,7 +83,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'], quiet=opts['quiet']) + diff=opts['installdiff'], debug=opts['debug']) installed = [] for dotfile in dotfiles: if hasattr(dotfile, 'link') and dotfile.link: @@ -131,7 +131,7 @@ def compare(opts, conf, tmp, focus=None): t = Templategen(base=opts['dotpath']) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], - quiet=opts['quiet']) + debug=opts['debug']) # compare only specific files ret = True @@ -158,8 +158,8 @@ def compare(opts, conf, tmp, focus=None): dotfile.src, dotfile.dst, opts=opts['dopts']) if same: - if not opts['quiet']: - LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, + if not opts['debug']: + LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst)) LOG.raw('same file') else: @@ -203,7 +203,7 @@ def update(opts, conf, path): if opts['safe'] and not LOG.ask(msg): return False else: - run(cmd, raw=False, log=False) + run(cmd, raw=False) LOG.log('\"%s\" updated from \"%s\".' % (src, path)) return True @@ -236,14 +236,14 @@ def importer(opts, conf, paths): if opts['dry']: LOG.dry('would run: %s' % (' '.join(cmd))) else: - run(cmd, raw=False, log=False) + run(cmd, raw=False) cmd = ['cp', '-R', '-L', dst, srcf] if opts['dry']: LOG.dry('would run: %s' % (' '.join(cmd))) if opts['link']: LOG.dry('would symlink %s to %s' % (srcf, dst)) else: - run(cmd, raw=False, log=False) + run(cmd, raw=False) if opts['link']: remove(dst) os.symlink(srcf, dst) @@ -299,7 +299,10 @@ def main(): opts['safe'] = not args['--force'] opts['installdiff'] = not args['--nodiff'] opts['link'] = args['--link'] - opts['quiet'] = not args['--verbose'] + opts['debug'] = not args['--verbose'] + + if opts['debug']: + LOG.debug = True header() diff --git a/dotdrop/installer.py b/dotdrop/installer.py index b8ef8f8..382de9f 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -16,16 +16,16 @@ class Installer: BACKUP_SUFFIX = '.dotdropbak' def __init__(self, base='.', create=True, backup=True, - dry=False, safe=False, quiet=False, diff=True): + dry=False, safe=False, debug=False, diff=True): self.create = create self.backup = backup self.dry = dry self.safe = safe self.base = base - self.quiet = quiet + self.debug = debug self.diff = diff self.comparing = False - self.log = Logger() + self.log = Logger(debug=self.debug) def install(self, templater, profile, src, dst): '''Install the dotfile for profile "profile"''' @@ -83,8 +83,7 @@ class Installer: self.log.err('installing \"%s\" to \"%s\"' % (src, dst)) return [] if ret > 0: - if not self.quiet: - self.log.sub('ignoring \"%s\", same content' % (dst)) + self.log.dbg('ignoring \"%s\", same content' % (dst)) return [] if ret == 0: if not self.dry and not self.comparing: @@ -189,8 +188,7 @@ class Installer: src, dst, tmpfolder) if ret: - diff = utils.diff(tmpdst, dst, log=False, - raw=False, opts=opts) + diff = utils.diff(tmpdst, dst, raw=False, opts=opts) if diff == '': retval = True, '' else: diff --git a/dotdrop/logger.py b/dotdrop/logger.py index d242ab3..f27786d 100644 --- a/dotdrop/logger.py +++ b/dotdrop/logger.py @@ -17,8 +17,8 @@ class Logger: RESET = '\033[0m' EMPH = '\033[33m' - def __init__(self): - pass + def __init__(self, debug=False): + self.debug = debug def log(self, string, end='\n', pre=''): cs = self._color(self.BLUE) @@ -45,6 +45,11 @@ class Logger: ce = self._color(self.RESET) sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce)) + def dbg(self, string): + cs = self._color(self.MAGENTA) + ce = self._color(self.RESET) + sys.stderr.write('%s[DEBUG] %s%s\n' % (cs, string, ce)) + def dry(self, string, end='\n'): cs = self._color(self.GREEN) ce = self._color(self.RESET) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 4ce2731..4b0f868 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -14,13 +14,8 @@ from shutil import rmtree from dotdrop.logger import Logger -LOG = Logger() - - -def run(cmd, log=False, raw=True): - """ expects a list """ - if log: - LOG.log('cmd: \"%s\"' % (' '.join(cmd))) +def run(cmd, raw=True): + ''' expects a list ''' p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if raw: @@ -29,10 +24,10 @@ def run(cmd, log=False, raw=True): return ''.join(lines) -def diff(src, dst, log=False, raw=True, opts=''): +def diff(src, dst, raw=True, opts=''): ''' call diff to compare two files ''' cmd = 'diff -r %s \"%s\" \"%s\"' % (opts, src, dst) - return run(shlex.split(cmd), log=log, raw=raw) + return run(shlex.split(cmd), raw=raw) def get_tmpdir(): diff --git a/tests/helpers.py b/tests/helpers.py index 69b737c..301d954 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -71,7 +71,7 @@ def load_config(confpath, profile): opts['safe'] = True opts['installdiff'] = True opts['link'] = False - opts['quiet'] = True + opts['debug'] = True opts['dopts'] = '' return conf, opts diff --git a/tests/test_compare.py b/tests/test_compare.py index 89729a0..25e82b9 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -31,7 +31,7 @@ class TestCompare(unittest.TestCase): self.assertTrue(len(dotfiles) == nbdotfiles) 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'], debug=True) results = {} for dotfile in dotfiles: same, _ = inst.compare(t, tmp, opts['profile'], diff --git a/tests/test_install.py b/tests/test_install.py index e190bc8..c2cd5d1 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -160,7 +160,7 @@ exec bspwm # install them conf, opts = load_config(confpath, profile) opts['safe'] = False - opts['quiet'] = True + opts['debug'] = True install(opts, conf) # now compare the generated files