mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 01:44:16 +00:00
implement transformations
This commit is contained in:
@@ -45,6 +45,7 @@ CUR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
LOG = Logger()
|
LOG = Logger()
|
||||||
HOSTNAME = os.uname()[1]
|
HOSTNAME = os.uname()[1]
|
||||||
TILD = '~'
|
TILD = '~'
|
||||||
|
TRANS_SUFFIX = 'trans'
|
||||||
|
|
||||||
BANNER = """ _ _ _
|
BANNER = """ _ _ _
|
||||||
__| | ___ | |_ __| |_ __ ___ _ __
|
__| | ___ | |_ __| |_ __ ___ _ __
|
||||||
@@ -101,12 +102,29 @@ def install(opts, conf):
|
|||||||
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:
|
||||||
|
src = dotfile.src
|
||||||
|
tmp = None
|
||||||
if dotfile.trans:
|
if dotfile.trans:
|
||||||
# TODO
|
tmp = '%s.%s' % (src, TRANS_SUFFIX)
|
||||||
tmp = get_tmpfile()
|
err = False
|
||||||
for trans in dotfile.trans:
|
for trans in dotfile.trans:
|
||||||
pass
|
s = os.path.join(opts['dotpath'], src)
|
||||||
r = inst.install(t, opts['profile'], dotfile.src, dotfile.dst)
|
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:
|
if len(r) > 0 and len(dotfile.actions) > 0:
|
||||||
# execute action
|
# execute action
|
||||||
for action in dotfile.actions:
|
for action in dotfile.actions:
|
||||||
@@ -145,6 +163,10 @@ def compare(opts, conf, tmp, focus=None):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
for dotfile in selected:
|
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'],
|
same, diff = inst.compare(t, tmp, opts['profile'],
|
||||||
dotfile.src, dotfile.dst,
|
dotfile.src, dotfile.dst,
|
||||||
opts=opts['dopts'])
|
opts=opts['dopts'])
|
||||||
|
|||||||
Reference in New Issue
Block a user