1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 04:29:47 +00:00

transformations first steps

This commit is contained in:
deadc0de6
2018-02-07 10:21:15 +01:00
parent fa62ffeef7
commit ef1fffd1a1
4 changed files with 28 additions and 2 deletions

View File

@@ -24,6 +24,18 @@ class Action:
except KeyboardInterrupt:
self.log.warn('action interrupted')
def transform(self, arg0, arg1):
'''execute transformation with {0} and {1}
where {0} is the file to transform and
{1} is the result file'''
cmd = self.action.format(arg0, arg1)
self.log.sub('transforming with \"%s\"' % (cmd))
try:
subprocess.call(cmd, shell=True)
except KeyboardInterrupt:
self.log.warn('action interrupted')
return arg1
def __str__(self):
return 'key:%s -> \"%s\"' % (self.key, self.action)

View File

@@ -130,8 +130,13 @@ class Cfg:
entries = v[self.key_dotfiles_trans] if \
self.key_dotfiles_trans in v else []
trans = self._parse_actions(self.trans, entries)
self.dotfiles[k] = Dotfile(k, dst, src,
link=link, actions=actions
if len(trans) > 0 and link:
msg = 'transformations disabled for \"%s\"' % (dst)
msg += ' as link is True' % (dst)
self.log.warn(msg)
trans = []
self.dotfiles[k] = Dotfile(k, dst, src, link=link,
actions=actions,
trans=trans)
# assign dotfiles to each profile

View File

@@ -101,6 +101,11 @@ def install(opts, conf):
if hasattr(dotfile, 'link') and dotfile.link:
r = inst.link(dotfile.src, dotfile.dst)
else:
if dotfile.trans:
# TODO
tmp = get_tmpfile()
for trans in dotfile.trans:
pass
r = inst.install(t, opts['profile'], dotfile.src, dotfile.dst)
if len(r) > 0 and len(dotfile.actions) > 0:
# execute action

View File

@@ -38,6 +38,10 @@ def get_tmpdir():
return tempfile.mkdtemp(prefix='dotdrop-')
def get_tmpfile():
return tempfile.mkstemp(prefix='dotdrop-')
def remove(path):
''' Remove a file / directory / symlink '''
if not os.path.exists(path):