mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 03:59:17 +00:00
adding transformations in config and dotfiles
This commit is contained in:
@@ -18,6 +18,7 @@ class Cfg:
|
|||||||
key_config = 'config'
|
key_config = 'config'
|
||||||
key_dotfiles = 'dotfiles'
|
key_dotfiles = 'dotfiles'
|
||||||
key_actions = 'actions'
|
key_actions = 'actions'
|
||||||
|
key_trans = 'trans'
|
||||||
key_dotpath = 'dotpath'
|
key_dotpath = 'dotpath'
|
||||||
key_profiles = 'profiles'
|
key_profiles = 'profiles'
|
||||||
key_profiles_dots = 'dotfiles'
|
key_profiles_dots = 'dotfiles'
|
||||||
@@ -26,6 +27,7 @@ class Cfg:
|
|||||||
key_dotfiles_dst = 'dst'
|
key_dotfiles_dst = 'dst'
|
||||||
key_dotfiles_link = 'link'
|
key_dotfiles_link = 'link'
|
||||||
key_dotfiles_actions = 'actions'
|
key_dotfiles_actions = 'actions'
|
||||||
|
key_dotfiles_trans = 'trans'
|
||||||
|
|
||||||
def __init__(self, cfgpath):
|
def __init__(self, cfgpath):
|
||||||
if not os.path.exists(cfgpath):
|
if not os.path.exists(cfgpath):
|
||||||
@@ -41,6 +43,8 @@ class Cfg:
|
|||||||
# not linked to content
|
# not linked to content
|
||||||
self.actions = {}
|
self.actions = {}
|
||||||
# not linked to content
|
# not linked to content
|
||||||
|
self.trans = {}
|
||||||
|
# not linked to content
|
||||||
self.prodots = {}
|
self.prodots = {}
|
||||||
if not self._load_file():
|
if not self._load_file():
|
||||||
raise ValueError('config is not valid')
|
raise ValueError('config is not valid')
|
||||||
@@ -94,6 +98,12 @@ class Cfg:
|
|||||||
for k, v in self.content[self.key_actions].items():
|
for k, v in self.content[self.key_actions].items():
|
||||||
self.actions[k] = Action(k, v)
|
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
|
# parse the profiles
|
||||||
self.profiles = self.content[self.key_profiles]
|
self.profiles = self.content[self.key_profiles]
|
||||||
if self.profiles is None:
|
if self.profiles is None:
|
||||||
@@ -117,8 +127,12 @@ class Cfg:
|
|||||||
entries = v[self.key_dotfiles_actions] if \
|
entries = v[self.key_dotfiles_actions] if \
|
||||||
self.key_dotfiles_actions in v else []
|
self.key_dotfiles_actions in v else []
|
||||||
actions = self._parse_actions(self.actions, entries)
|
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,
|
self.dotfiles[k] = Dotfile(k, dst, src,
|
||||||
link=link, actions=actions)
|
link=link, actions=actions
|
||||||
|
trans=trans)
|
||||||
|
|
||||||
# assign dotfiles to each profile
|
# assign dotfiles to each profile
|
||||||
for k, v in self.profiles.items():
|
for k, v in self.profiles.items():
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ represents a dotfile in dotdrop
|
|||||||
|
|
||||||
class Dotfile:
|
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
|
# key of dotfile in the config
|
||||||
self.key = key
|
self.key = key
|
||||||
# where to install this dotfile
|
# where to install this dotfile
|
||||||
@@ -18,6 +19,8 @@ class Dotfile:
|
|||||||
self.link = link
|
self.link = link
|
||||||
# list of actions
|
# list of actions
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
|
# list of transformations
|
||||||
|
self.trans = trans
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'key:%s, src: %s, dst: %s, link: %s' % (self.key, self.src,
|
return 'key:%s, src: %s, dst: %s, link: %s' % (self.key, self.src,
|
||||||
|
|||||||
Reference in New Issue
Block a user