1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 05:58:59 +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']) diff=opts['installdiff'], debug=opts['debug'])
installed = [] installed = []
for dotfile in dotfiles: for dotfile in dotfiles:
LOG.dbg('installing {}'.format(dotfile))
if hasattr(dotfile, 'link') and dotfile.link: if hasattr(dotfile, 'link') and dotfile.link:
r = inst.link(dotfile.src, dotfile.dst) r = inst.link(dotfile.src, dotfile.dst)
else: else:
@@ -95,6 +96,7 @@ def install(opts, conf):
tmp = '%s.%s' % (src, TRANS_SUFFIX) tmp = '%s.%s' % (src, TRANS_SUFFIX)
err = False err = False
for trans in dotfile.trans: for trans in dotfile.trans:
LOG.dbg('executing transformation {}'.format(trans))
s = os.path.join(opts['dotpath'], src) s = os.path.join(opts['dotpath'], src)
temp = os.path.join(opts['dotpath'], tmp) temp = os.path.join(opts['dotpath'], tmp)
if not trans.transform(s, temp): if not trans.transform(s, temp):
@@ -115,6 +117,7 @@ def install(opts, conf):
if len(r) > 0 and len(dotfile.actions) > 0: if len(r) > 0 and len(dotfile.actions) > 0:
# execute action # execute action
for action in dotfile.actions: for action in dotfile.actions:
LOG.dbg('executing action {}'.format(action))
action.execute() action.execute()
installed.extend(r) installed.extend(r)
LOG.log('\n%u dotfile(s) installed.' % (len(installed))) LOG.log('\n%u dotfile(s) installed.' % (len(installed)))
@@ -150,6 +153,7 @@ def compare(opts, conf, tmp, focus=None):
return ret return ret
for dotfile in selected: for dotfile in selected:
LOG.dbg('comparing {}'.format(dotfile))
if dotfile.trans: if dotfile.trans:
msg = 'ignore %s as it uses transformation(s)' msg = 'ignore %s as it uses transformation(s)'
LOG.log(msg % (dotfile.key)) LOG.log(msg % (dotfile.key))
@@ -158,10 +162,9 @@ def compare(opts, conf, tmp, focus=None):
dotfile.src, dotfile.dst, dotfile.src, dotfile.dst,
opts=opts['dopts']) opts=opts['dopts'])
if same: if same:
if not opts['debug']: LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
LOG.dbg('diffing \"%s\" VS \"%s\"' % (dotfile.key,
dotfile.dst)) dotfile.dst))
LOG.raw('same file') LOG.dbg('same file')
else: else:
LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst)) LOG.log('diffing \"%s\" VS \"%s\"' % (dotfile.key, dotfile.dst))
LOG.emph(diff) LOG.emph(diff)
@@ -299,10 +302,10 @@ def 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['debug'] = not args['--verbose'] opts['debug'] = args['--verbose']
if opts['debug']: LOG.debug = opts['debug']
LOG.debug = True LOG.dbg('opts: {}'.format(opts))
header() header()

View File

@@ -23,7 +23,7 @@ class Dotfile:
self.trans = trans self.trans = trans
def __str__(self): 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) self.dst, self.link)
def __eq__(self, other): def __eq__(self, other):

View File

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

View File

@@ -5,6 +5,7 @@ handle logging to stdout/stderr
""" """
import sys import sys
import inspect
class Logger: class Logger:
@@ -46,9 +47,14 @@ class Logger:
sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce)) sys.stderr.write('%s[WARN] %s %s%s' % (cs, string, end, ce))
def dbg(self, string): 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) cs = self._color(self.MAGENTA)
ce = self._color(self.RESET) 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'): def dry(self, string, end='\n'):
cs = self._color(self.GREEN) cs = self._color(self.GREEN)