1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-11 17:49:01 +00:00

ensure pre action are only executed once

This commit is contained in:
deadc0de6
2018-09-25 07:25:58 +02:00
parent 67ae4bec8b
commit ef9718165e
2 changed files with 15 additions and 8 deletions

View File

@@ -96,12 +96,7 @@ def install(opts, conf, temporary=False):
preactions = [] preactions = []
if dotfile.actions and Cfg.key_actions_pre in dotfile.actions: if dotfile.actions and Cfg.key_actions_pre in dotfile.actions:
for action in dotfile.actions[Cfg.key_actions_pre]: for action in dotfile.actions[Cfg.key_actions_pre]:
if opts['dry']: preactions.append(action)
LOG.dry('would execute action: {}'.format(action))
else:
if opts['debug']:
LOG.dbg('executing pre action {}'.format(action))
preactions.append(action)
if opts['debug']: if opts['debug']:
LOG.dbg('installing {}'.format(dotfile)) LOG.dbg('installing {}'.format(dotfile))
if hasattr(dotfile, 'link') and dotfile.link: if hasattr(dotfile, 'link') and dotfile.link:

View File

@@ -31,10 +31,12 @@ class Installer:
self.diff = diff self.diff = diff
self.totemp = totemp self.totemp = totemp
self.comparing = False self.comparing = False
self.action_executed = False
self.log = Logger() self.log = Logger()
def install(self, templater, src, dst, actions=[]): def install(self, templater, src, dst, actions=[]):
"""install the src to dst using a template""" """install the src to dst using a template"""
self.action_executed = False
src = os.path.join(self.base, os.path.expanduser(src)) src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
if self.totemp: if self.totemp:
@@ -51,10 +53,12 @@ class Installer:
def link(self, templater, src, dst, actions=[]): def link(self, templater, src, dst, actions=[]):
"""set src as the link target of dst""" """set src as the link target of dst"""
self.action_executed = False
src = os.path.join(self.base, os.path.expanduser(src)) src = os.path.join(self.base, os.path.expanduser(src))
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
if self.totemp: 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 Templategen.is_template(src):
if self.debug: if self.debug:
@@ -220,8 +224,16 @@ class Installer:
def _exec_pre_actions(self, actions): def _exec_pre_actions(self, actions):
"""execute pre-actions if any""" """execute pre-actions if any"""
if self.action_executed:
return
for action in actions: 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): def _install_to_temp(self, templater, src, dst, tmpdir):
"""install a dotfile to a tempdir""" """install a dotfile to a tempdir"""