1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 01:34:42 +00:00

adding transformations in config and dotfiles

This commit is contained in:
deadc0de6
2018-02-07 09:50:57 +01:00
parent 39d7dbbe24
commit fa62ffeef7
2 changed files with 19 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ class Cfg:
key_config = 'config'
key_dotfiles = 'dotfiles'
key_actions = 'actions'
key_trans = 'trans'
key_dotpath = 'dotpath'
key_profiles = 'profiles'
key_profiles_dots = 'dotfiles'
@@ -26,6 +27,7 @@ class Cfg:
key_dotfiles_dst = 'dst'
key_dotfiles_link = 'link'
key_dotfiles_actions = 'actions'
key_dotfiles_trans = 'trans'
def __init__(self, cfgpath):
if not os.path.exists(cfgpath):
@@ -41,6 +43,8 @@ class Cfg:
# not linked to content
self.actions = {}
# not linked to content
self.trans = {}
# not linked to content
self.prodots = {}
if not self._load_file():
raise ValueError('config is not valid')
@@ -94,6 +98,12 @@ class Cfg:
for k, v in self.content[self.key_actions].items():
self.actions[k] = Action(k, v)
# parse all transformations
if self.key_trans in self.content:
if self.content[self.key_trans] is not None:
for k, v in self.content[self.key_trans].items():
self.trans[k] = Action(k, v)
# parse the profiles
self.profiles = self.content[self.key_profiles]
if self.profiles is None:
@@ -117,8 +127,12 @@ class Cfg:
entries = v[self.key_dotfiles_actions] if \
self.key_dotfiles_actions in v else []
actions = self._parse_actions(self.actions, entries)
entries = v[self.key_dotfiles_trans] if \
self.key_dotfiles_trans in v else []
trans = self._parse_actions(self.trans, entries)
self.dotfiles[k] = Dotfile(k, dst, src,
link=link, actions=actions)
link=link, actions=actions
trans=trans)
# assign dotfiles to each profile
for k, v in self.profiles.items():

View File

@@ -7,7 +7,8 @@ represents a dotfile in dotdrop
class Dotfile:
def __init__(self, key, dst, src, actions=[], link=False):
def __init__(self, key, dst, src,
actions=[], trans=[], link=False):
# key of dotfile in the config
self.key = key
# where to install this dotfile
@@ -18,6 +19,8 @@ class Dotfile:
self.link = link
# list of actions
self.actions = actions
# list of transformations
self.trans = trans
def __str__(self):
return 'key:%s, src: %s, dst: %s, link: %s' % (self.key, self.src,