From 262dd45823d0b59db6d77537ea8a96848f756546 Mon Sep 17 00:00:00 2001 From: moyiz Date: Wed, 3 May 2017 10:04:14 +0300 Subject: [PATCH] Add link support to config file and dotfile --- dotdrop/config.py | 8 +++++--- dotdrop/dotfile.py | 9 +++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dotdrop/config.py b/dotdrop/config.py index 5cd02b2..9757dad 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -18,6 +18,7 @@ class Cfg: key_dotpath = 'dotpath' key_dotfiles_src = 'src' key_dotfiles_dst = 'dst' + key_dotfiles_link = 'link' def __init__(self, cfgpath): if not os.path.exists(cfgpath): @@ -61,7 +62,9 @@ class Cfg: for k, v in self.content[self.key_dotfiles].items(): src = v[self.key_dotfiles_src] dst = v[self.key_dotfiles_dst] - self.dotfiles[k] = Dotfile(k, dst, src) + link = v[self.key_dotfiles_link] if self.key_dotfiles_link in v + else False + self.dotfiles[k] = Dotfile(k, dst, src, link) # contains a list of dotfiles defined for each profile for k, v in self.profiles.items(): self.prodots[k] = [] @@ -115,8 +118,7 @@ class Cfg: """ returns a list of dotfiles for a specific profile """ if profile not in self.prodots: return [] - tmp = sorted(self.prodots[profile], key=lambda x: x.key, reverse=True) - return tmp + return sorted(self.prodots[profile], key=lambda x: x.key, reverse=True) def get_profiles(self): """ returns all defined profiles """ diff --git a/dotdrop/dotfile.py b/dotdrop/dotfile.py index c696631..a7e53b0 100644 --- a/dotdrop/dotfile.py +++ b/dotdrop/dotfile.py @@ -7,15 +7,16 @@ represents a dotfile in dotdrop class Dotfile: - def __init__(self, key, dst, src): + def __init__(self, key, dst, src, link=False): # key of dotfile in the config self.key = key # where to install this dotfile self.dst = dst # stored dotfile in dotdrop self.src = src + # should be a link + self.link = link def __str__(self): - string = 'key:%s, src: %s, dst: %s' % (self.key, - self.src, self.dst) - return string + return 'key:%s, src: %s, dst: %s, link: %s' % (self.key, self.src, + self.dst, self.link)