From ef9718165e647fdfc179564adae869b2172945e1 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 25 Sep 2018 07:25:58 +0200 Subject: [PATCH] ensure pre action are only executed once --- dotdrop/dotdrop.py | 7 +------ dotdrop/installer.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 217670d..d80e58c 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -96,12 +96,7 @@ def install(opts, conf, temporary=False): preactions = [] if dotfile.actions and Cfg.key_actions_pre in dotfile.actions: for action in dotfile.actions[Cfg.key_actions_pre]: - if opts['dry']: - LOG.dry('would execute action: {}'.format(action)) - else: - if opts['debug']: - LOG.dbg('executing pre action {}'.format(action)) - preactions.append(action) + preactions.append(action) if opts['debug']: LOG.dbg('installing {}'.format(dotfile)) if hasattr(dotfile, 'link') and dotfile.link: diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 246e347..63fa09c 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -31,10 +31,12 @@ class Installer: self.diff = diff self.totemp = totemp self.comparing = False + self.action_executed = False self.log = Logger() def install(self, templater, src, dst, actions=[]): """install the src to dst using a template""" + self.action_executed = False src = os.path.join(self.base, os.path.expanduser(src)) dst = os.path.expanduser(dst) if self.totemp: @@ -51,10 +53,12 @@ class Installer: def link(self, templater, src, dst, actions=[]): """set src as the link target of dst""" + self.action_executed = False src = os.path.join(self.base, os.path.expanduser(src)) dst = os.path.expanduser(dst) if self.totemp: - return self.install(templater, src, dst, actions=actions) + # ignore actions + return self.install(templater, src, dst, actions=[]) if Templategen.is_template(src): if self.debug: @@ -220,8 +224,16 @@ class Installer: def _exec_pre_actions(self, actions): """execute pre-actions if any""" + if self.action_executed: + return for action in actions: - action.execute() + if self.dry: + self.log.dry('would execute action: {}'.format(action)) + else: + if self.debug: + self.log.dbg('executing pre action {}'.format(action)) + action.execute() + self.action_executed = True def _install_to_temp(self, templater, src, dst, tmpdir): """install a dotfile to a tempdir"""