diff --git a/dotdrop/action.py b/dotdrop/action.py index e463f4d..51676cd 100644 --- a/dotdrop/action.py +++ b/dotdrop/action.py @@ -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) diff --git a/dotdrop/config.py b/dotdrop/config.py index 9d0d2ad..29a5c20 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -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 diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 6840bcf..a506a22 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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 diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 45765d5..844a37c 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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):