mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 04:59:15 +00:00
fix profile actions for #152
This commit is contained in:
@@ -28,7 +28,7 @@ TRANS_SUFFIX = 'trans'
|
|||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
|
|
||||||
def action_executor(o, dotfile, actions, defactions, templater, post=False):
|
def action_executor(o, actions, defactions, templater, post=False):
|
||||||
"""closure for action execution"""
|
"""closure for action execution"""
|
||||||
def execute():
|
def execute():
|
||||||
"""
|
"""
|
||||||
@@ -71,6 +71,10 @@ def action_executor(o, dotfile, actions, defactions, templater, post=False):
|
|||||||
def cmd_install(o):
|
def cmd_install(o):
|
||||||
"""install dotfiles for this profile"""
|
"""install dotfiles for this profile"""
|
||||||
dotfiles = o.dotfiles
|
dotfiles = o.dotfiles
|
||||||
|
prof = o.conf.get_profile(o.profile)
|
||||||
|
pro_pre_actions = prof.get_pre_actions()
|
||||||
|
pro_post_actions = prof.get_post_actions()
|
||||||
|
|
||||||
if o.install_keys:
|
if o.install_keys:
|
||||||
# filtered dotfiles to install
|
# filtered dotfiles to install
|
||||||
uniq = uniq_list(o.install_keys)
|
uniq = uniq_list(o.install_keys)
|
||||||
@@ -94,6 +98,15 @@ def cmd_install(o):
|
|||||||
backup_suffix=o.install_backup_suffix)
|
backup_suffix=o.install_backup_suffix)
|
||||||
installed = 0
|
installed = 0
|
||||||
tvars = t.add_tmp_vars()
|
tvars = t.add_tmp_vars()
|
||||||
|
|
||||||
|
# execute profile pre-action
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('execute profile pre actions')
|
||||||
|
ret, err = action_executor(o, pro_pre_actions, [], t, post=False)()
|
||||||
|
if not ret:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# install each dotfile
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
# add dotfile variables
|
# add dotfile variables
|
||||||
t.restore_vars(tvars)
|
t.restore_vars(tvars)
|
||||||
@@ -103,11 +116,9 @@ def cmd_install(o):
|
|||||||
preactions = []
|
preactions = []
|
||||||
if not o.install_temporary:
|
if not o.install_temporary:
|
||||||
preactions.extend(dotfile.get_pre_actions())
|
preactions.extend(dotfile.get_pre_actions())
|
||||||
prof = o.conf.get_profile(o.profile)
|
|
||||||
preactions.extend(prof.get_pre_actions())
|
|
||||||
defactions = o.install_default_actions_pre
|
defactions = o.install_default_actions_pre
|
||||||
pre_actions_exec = action_executor(o, dotfile, preactions,
|
pre_actions_exec = action_executor(o, preactions, defactions,
|
||||||
defactions, t, post=False)
|
t, post=False)
|
||||||
|
|
||||||
if o.debug:
|
if o.debug:
|
||||||
LOG.dbg('installing {}'.format(dotfile))
|
LOG.dbg('installing {}'.format(dotfile))
|
||||||
@@ -138,29 +149,35 @@ def cmd_install(o):
|
|||||||
if not o.install_temporary:
|
if not o.install_temporary:
|
||||||
defactions = o.install_default_actions_post
|
defactions = o.install_default_actions_post
|
||||||
postactions = dotfile.get_post_actions()
|
postactions = dotfile.get_post_actions()
|
||||||
prof = o.conf.get_profile(o.profile)
|
post_actions_exec = action_executor(o, postactions, defactions,
|
||||||
postactions.extend(prof.get_post_actions())
|
t, post=True)
|
||||||
post_actions_exec = action_executor(o, dotfile, postactions,
|
|
||||||
defactions, t, post=True)
|
|
||||||
post_actions_exec()
|
post_actions_exec()
|
||||||
installed += 1
|
installed += 1
|
||||||
elif not r:
|
elif not r:
|
||||||
# dotfile was NOT installed
|
# dotfile was NOT installed
|
||||||
if o.install_force_action:
|
if o.install_force_action:
|
||||||
# pre-actions
|
# pre-actions
|
||||||
LOG.dbg('force pre action execution ...')
|
if o.debug:
|
||||||
|
LOG.dbg('force pre action execution ...')
|
||||||
pre_actions_exec()
|
pre_actions_exec()
|
||||||
# post-actions
|
# post-actions
|
||||||
LOG.dbg('force post action execution ...')
|
LOG.dbg('force post action execution ...')
|
||||||
postactions = dotfile.get_post_actions()
|
postactions = dotfile.get_post_actions()
|
||||||
prof = o.conf.get_profile(o.profile)
|
post_actions_exec = action_executor(o, postactions, defactions,
|
||||||
postactions.extend(prof.get_post_actions())
|
t, post=True)
|
||||||
post_actions_exec = action_executor(o, dotfile, postactions,
|
|
||||||
defactions, t, post=True)
|
|
||||||
post_actions_exec()
|
post_actions_exec()
|
||||||
if err:
|
if err:
|
||||||
LOG.err('installing \"{}\" failed: {}'.format(dotfile.key,
|
LOG.err('installing \"{}\" failed: {}'.format(dotfile.key,
|
||||||
err))
|
err))
|
||||||
|
|
||||||
|
# execute profile post-action
|
||||||
|
if installed > 0 or o.install_force_action:
|
||||||
|
if o.debug:
|
||||||
|
LOG.dbg('execute profile post actions')
|
||||||
|
ret, err = action_executor(o, pro_post_actions, [], t, post=False)()
|
||||||
|
if not ret:
|
||||||
|
return False
|
||||||
|
|
||||||
if o.install_temporary:
|
if o.install_temporary:
|
||||||
LOG.log('\ninstalled to tmp \"{}\".'.format(tmpdir))
|
LOG.log('\ninstalled to tmp \"{}\".'.format(tmpdir))
|
||||||
LOG.log('\n{} dotfile(s) installed.'.format(installed))
|
LOG.log('\n{} dotfile(s) installed.'.format(installed))
|
||||||
|
|||||||
Reference in New Issue
Block a user