1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 18:34:48 +00:00

rename quiet as debug

This commit is contained in:
deadc0de6
2018-05-02 20:29:36 +02:00
parent 24ef632f4c
commit 881537443b
7 changed files with 30 additions and 29 deletions

View File

@@ -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()

View File

@@ -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:

View File

@@ -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)

View File

@@ -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():

View File

@@ -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

View File

@@ -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'],

View File

@@ -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