1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 06:48:49 +00:00

adding more debugging info

This commit is contained in:
deadc0de6
2018-05-02 21:08:52 +02:00
parent 927d76779f
commit f68ddeb06f
4 changed files with 24 additions and 8 deletions

View File

@@ -86,6 +86,7 @@ def install(opts, conf):
diff=opts['installdiff'], debug=opts['debug'])
installed = []
for dotfile in dotfiles:
LOG.dbg('installing {}'.format(dotfile))
if hasattr(dotfile, 'link') and dotfile.link:
r = inst.link(dotfile.src, dotfile.dst)
else:
@@ -95,6 +96,7 @@ def install(opts, conf):
tmp = '%s.%s' % (src, TRANS_SUFFIX)
err = False
for trans in dotfile.trans:
LOG.dbg('executing transformation {}'.format(trans))
s = os.path.join(opts['dotpath'], src)
temp = os.path.join(opts['dotpath'], tmp)
if not trans.transform(s, temp):
@@ -115,6 +117,7 @@ def install(opts, conf):
if len(r) > 0 and len(dotfile.actions) > 0:
# execute action
for action in dotfile.actions:
LOG.dbg('executing action {}'.format(action))
action.execute()
installed.extend(r)
LOG.log('\n%u dotfile(s) installed.' % (len(installed)))
@@ -150,6 +153,7 @@ def compare(opts, conf, tmp, focus=None):
return ret
for dotfile in selected:
LOG.dbg('comparing {}'.format(dotfile))
if dotfile.trans:
msg = 'ignore %s as it uses transformation(s)'
LOG.log(msg % (dotfile.key))
@@ -158,10 +162,9 @@ def compare(opts, conf, tmp, focus=None):
dotfile.src, dotfile.dst,
opts=opts['dopts'])
if same:
if not opts['debug']:
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
dotfile.dst))
LOG.raw('same file')
LOG.dbg('same file')
else:
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
LOG.emph(diff)
@@ -299,10 +302,10 @@ def main():
opts['safe'] = not args['--force']
opts['installdiff'] = not args['--nodiff']
opts['link'] = args['--link']
opts['debug'] = not args['--verbose']
opts['debug'] = args['--verbose']
if opts['debug']:
LOG.debug = True
LOG.debug = opts['debug']
LOG.dbg('opts: {}'.format(opts))
header()

View File

@@ -23,7 +23,7 @@ class Dotfile:
self.trans = trans
def __str__(self):
return 'key:%s, src: %s, dst: %s, link: %s' % (self.key, self.src,
return 'key:\"%s\", src:\"%s\", dst:\"%s\", link:\"%s\"' % (self.key, self.src,
self.dst, self.link)
def __eq__(self, other):

View File

@@ -31,6 +31,7 @@ class Installer:
'''Install the dotfile for profile "profile"'''
src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.join(self.base, os.path.expanduser(dst))
self.log.dbg('install {} to {}'.format(src, dst))
if os.path.isdir(src):
return self._handle_dir(templater, profile, src, dst)
return self._handle_file(templater, profile, src, dst)
@@ -70,6 +71,7 @@ class Installer:
def _handle_file(self, templater, profile, src, dst):
'''Install a file using templater for "profile"'''
self.log.dbg('generate template for {}'.format(src))
content = templater.generate(src, profile)
if content is None:
self.log.err('generate from template \"%s\"' % (src))
@@ -124,6 +126,7 @@ class Installer:
if os.path.exists(dst):
samerights = os.stat(dst).st_mode == rights
if self.diff and self._fake_diff(dst, content) and samerights:
self.log.dbg('{} is the same'.format(dst))
return 1
if self.safe and not self.log.ask('Overwrite \"%s\"' % (dst)):
self.log.warn('ignoring \"%s\", already present' % (dst))
@@ -134,6 +137,7 @@ class Installer:
if not self._create_dirs(base):
self.log.err('creating directory for \"%s\"' % (dst))
return -1
self.log.dbg('write content to {}'.format(dst))
try:
with open(dst, 'wb') as f:
f.write(content)
@@ -149,6 +153,7 @@ class Installer:
return False
if os.path.exists(directory):
return True
self.log.dbg('mkdir -p {}'.format(directory))
os.makedirs(directory)
return os.path.exists(directory)
@@ -180,6 +185,7 @@ class Installer:
self.create = True
src = os.path.expanduser(src)
dst = os.path.expanduser(dst)
self.log.dbg('comparing {} and {}'.format(src, dst))
if not os.path.exists(dst):
retval = False, '\"%s\" does not exist on local\n' % (dst)
else:
@@ -188,6 +194,7 @@ class Installer:
src, dst,
tmpdir)
if ret:
self.log.dbg('diffing {} and {}'.format(tmpdst, dst))
diff = utils.diff(tmpdst, dst, raw=False, opts=opts)
if diff == '':
retval = True, ''

View File

@@ -5,6 +5,7 @@ handle logging to stdout/stderr
"""
import sys
import inspect
class Logger:
@@ -46,9 +47,14 @@ class Logger:
sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce))
def dbg(self, string):
if not self.debug:
return
frame = inspect.stack()[1]
mod = inspect.getmodule(frame[0]).__name__
func = inspect.stack()[1][3]
cs = self._color(self.MAGENTA)
ce = self._color(self.RESET)
sys.stderr.write('%s[DEBUG] %s%s\n' % (cs, string, ce))
sys.stderr.write('%s[DEBUG][%s.%s] %s%s\n' % (cs, mod, func, string, ce))
def dry(self, string, end='\n'):
cs = self._color(self.GREEN)