From 7c9d488fb31a99a76cbe2be0d1d69ec7d657a610 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 7 Feb 2018 16:38:03 +0100 Subject: [PATCH] implement transformations --- dotdrop/dotdrop.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index a506a22..2711444 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -45,6 +45,7 @@ CUR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) LOG = Logger() HOSTNAME = os.uname()[1] TILD = '~' +TRANS_SUFFIX = 'trans' BANNER = """ _ _ _ __| | ___ | |_ __| |_ __ ___ _ __ @@ -101,12 +102,29 @@ def install(opts, conf): if hasattr(dotfile, 'link') and dotfile.link: r = inst.link(dotfile.src, dotfile.dst) else: + src = dotfile.src + tmp = None if dotfile.trans: - # TODO - tmp = get_tmpfile() + tmp = '%s.%s' % (src, TRANS_SUFFIX) + err = False for trans in dotfile.trans: - pass - r = inst.install(t, opts['profile'], dotfile.src, dotfile.dst) + s = os.path.join(opts['dotpath'], src) + temp = os.path.join(opts['dotpath'], tmp) + if not trans.transform(s, temp): + msg = 'transformation \"%s\" failed for %s' + LOG.err(msg % (trans.key, dotfile.key)) + err = True + break + if err: + if tmp and os.path.exists(tmp): + remove(tmp) + continue + src = tmp + r = inst.install(t, opts['profile'], src, dotfile.dst) + if tmp: + tmp = os.path.join(opts['dotpath'], tmp) + if os.path.exists(tmp): + remove(tmp) if len(r) > 0 and len(dotfile.actions) > 0: # execute action for action in dotfile.actions: @@ -145,6 +163,10 @@ def compare(opts, conf, tmp, focus=None): return ret for dotfile in selected: + if dotfile.trans: + msg = 'ignore %s as it uses transformation(s)' + LOG.log(msg % (dotfile.key)) + continue same, diff = inst.compare(t, tmp, opts['profile'], dotfile.src, dotfile.dst, opts=opts['dopts'])