From 57a4b8ca52de27074b25664284221b09e64bcfe3 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 2 Jun 2018 09:36:15 +0200 Subject: [PATCH] correctly handle new created dotfile and existing ones --- dotdrop/config.py | 8 ++++---- dotdrop/dotdrop.py | 17 +++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/dotdrop/config.py b/dotdrop/config.py index 61b400d..2df8e68 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -281,7 +281,7 @@ class Cfg: return False, self._get_unique_key(dotfile.dst) def new(self, dotfile, profile, link=False): - """ import new dotfile (key is to be changed) """ + """ import new dotfile (key will change) """ # keep it short home = os.path.expanduser('~') @@ -298,7 +298,7 @@ class Cfg: # already in it if profile in self.prodots and dotfile in self.prodots[profile]: self.log.err('\"{}\" already present'.format(dotfile.key)) - return False + return False, dotfile # add for this profile if profile not in self.prodots: @@ -308,7 +308,7 @@ class Cfg: ent = self.content[self.key_profiles][profile] if self.key_all not in ent[self.key_profiles_dots]: ent[self.key_profiles_dots].append(dotfile.key) - return True + return True, dotfile # adding the dotfile dotfile.key = key @@ -329,7 +329,7 @@ class Cfg: # adding to global list self.dotfiles[dotfile.key] = dotfile - return True + return True, dotfile def get_dotfiles(self, profile): """ returns a list of dotfiles for a specific profile """ diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index aa1c0f4..92cab14 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -232,21 +232,18 @@ def importer(opts, conf, paths): LOG.err('\"{}\" does not exist, ignored !'.format(path)) continue dst = path.rstrip(os.sep) - key = dst.split(os.sep)[-1] - if key == 'config': - key = '_'.join(dst.split(os.sep)[-2:]) - key = key.lstrip('.').lower() - if os.path.isdir(dst): - key = 'd_{}'.format(key) - else: - key = 'f_{}'.format(key) src = dst if dst.startswith(home): src = dst[len(home):] src = src.lstrip('.' + os.sep) - dotfile = Dotfile(key, dst, src) + + # create a new dotfile + dotfile = Dotfile('', dst, src) + retconf, new_dotfile = conf.new(dotfile, opts['profile'], opts['link']) + dotfile = new_dotfile + + # prepare hierarchy for dotfile srcf = os.path.join(CUR, opts['dotpath'], src) - retconf = conf.new(dotfile, opts['profile'], opts['link']) if not os.path.exists(srcf): cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))] if opts['dry']: