mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 09:03:00 +00:00
adding profile actions for #141
This commit is contained in:
@@ -83,13 +83,14 @@ class CfgAggregator:
|
||||
self._patch_keys_to_objs(self.profiles,
|
||||
"dotfiles", self.get_dotfile)
|
||||
|
||||
# patch action in actions
|
||||
# patch action in dotfiles actions
|
||||
self._patch_keys_to_objs(self.dotfiles,
|
||||
"actions", self._get_action_w_args)
|
||||
# patch action in profiles actions
|
||||
self._patch_keys_to_objs(self.profiles,
|
||||
"actions", self._get_action_w_args)
|
||||
|
||||
# patch default actions in settings
|
||||
# patch actions in settings default_actions
|
||||
self._patch_keys_to_objs([self.settings],
|
||||
"default_actions", self._get_action_w_args)
|
||||
if self.debug:
|
||||
@@ -254,6 +255,13 @@ class CfgAggregator:
|
||||
"""return profiles"""
|
||||
return self.profiles
|
||||
|
||||
def get_profile(self, key):
|
||||
"""return profile by key"""
|
||||
try:
|
||||
return next(x for x in self.profiles if x.key == key)
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
def get_dotfiles(self, profile=None):
|
||||
"""return dotfiles dict for this profile key"""
|
||||
if not profile:
|
||||
|
||||
@@ -101,6 +101,8 @@ def cmd_install(o):
|
||||
preactions = []
|
||||
if not o.install_temporary:
|
||||
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
|
||||
pre_actions_exec = action_executor(o, dotfile, preactions,
|
||||
defactions, t, post=False)
|
||||
@@ -134,6 +136,8 @@ def cmd_install(o):
|
||||
if not o.install_temporary:
|
||||
defactions = o.install_default_actions_post
|
||||
postactions = dotfile.get_post_actions()
|
||||
prof = o.conf.get_profile(o.profile)
|
||||
postactions.extend(prof.get_post_actions())
|
||||
post_actions_exec = action_executor(o, dotfile, postactions,
|
||||
defactions, t, post=True)
|
||||
post_actions_exec()
|
||||
@@ -145,6 +149,8 @@ def cmd_install(o):
|
||||
pre_actions_exec()
|
||||
LOG.dbg('force post pre action execution ...')
|
||||
postactions = dotfile.get_post_actions()
|
||||
prof = o.conf.get_profile(o.profile)
|
||||
postactions.extend(prof.get_post_actions())
|
||||
post_actions_exec = action_executor(o, dotfile, postactions,
|
||||
defactions, t, post=True)
|
||||
post_actions_exec()
|
||||
|
||||
@@ -51,7 +51,8 @@ USAGE = """
|
||||
|
||||
Usage:
|
||||
dotdrop install [-VbtfndDa] [-c <path>] [-p <profile>] [<key>...]
|
||||
dotdrop import [-Vbd] [-c <path>] [-p <profile>] [-l <link>] <path>...
|
||||
dotdrop import [-Vbd] [-c <path>] [-p <profile>]
|
||||
[-l <link>] <path>...
|
||||
dotdrop compare [-Vb] [-c <path>] [-p <profile>]
|
||||
[-o <opts>] [-C <file>...] [-i <pattern>...]
|
||||
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
||||
|
||||
@@ -6,6 +6,7 @@ represent a profile in dotdrop
|
||||
"""
|
||||
|
||||
from dotdrop.dictparser import DictParser
|
||||
from dotdrop.action import Action
|
||||
|
||||
|
||||
class Profile(DictParser):
|
||||
@@ -27,6 +28,14 @@ class Profile(DictParser):
|
||||
self.dotfiles = dotfiles
|
||||
self.variables = variables
|
||||
|
||||
def get_pre_actions(self):
|
||||
"""return all 'pre' actions"""
|
||||
return [a for a in self.actions if a.kind == Action.pre]
|
||||
|
||||
def get_post_actions(self):
|
||||
"""return all 'post' actions"""
|
||||
return [a for a in self.actions if a.kind == Action.post]
|
||||
|
||||
@classmethod
|
||||
def _adjust_yaml_keys(cls, value):
|
||||
"""patch dict"""
|
||||
|
||||
Reference in New Issue
Block a user