mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 10:53:49 +00:00
ensure pre action are only executed once
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user