mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 09:29:17 +00:00
correctly handle new created dotfile and existing ones
This commit is contained in:
@@ -281,7 +281,7 @@ class Cfg:
|
|||||||
return False, self._get_unique_key(dotfile.dst)
|
return False, self._get_unique_key(dotfile.dst)
|
||||||
|
|
||||||
def new(self, dotfile, profile, link=False):
|
def new(self, dotfile, profile, link=False):
|
||||||
""" import new dotfile (key is to be changed) """
|
""" import new dotfile (key will change) """
|
||||||
|
|
||||||
# keep it short
|
# keep it short
|
||||||
home = os.path.expanduser('~')
|
home = os.path.expanduser('~')
|
||||||
@@ -298,7 +298,7 @@ class Cfg:
|
|||||||
# already in it
|
# already in it
|
||||||
if profile in self.prodots and dotfile in self.prodots[profile]:
|
if profile in self.prodots and dotfile in self.prodots[profile]:
|
||||||
self.log.err('\"{}\" already present'.format(dotfile.key))
|
self.log.err('\"{}\" already present'.format(dotfile.key))
|
||||||
return False
|
return False, dotfile
|
||||||
|
|
||||||
# add for this profile
|
# add for this profile
|
||||||
if profile not in self.prodots:
|
if profile not in self.prodots:
|
||||||
@@ -308,7 +308,7 @@ class Cfg:
|
|||||||
ent = self.content[self.key_profiles][profile]
|
ent = self.content[self.key_profiles][profile]
|
||||||
if self.key_all not in ent[self.key_profiles_dots]:
|
if self.key_all not in ent[self.key_profiles_dots]:
|
||||||
ent[self.key_profiles_dots].append(dotfile.key)
|
ent[self.key_profiles_dots].append(dotfile.key)
|
||||||
return True
|
return True, dotfile
|
||||||
|
|
||||||
# adding the dotfile
|
# adding the dotfile
|
||||||
dotfile.key = key
|
dotfile.key = key
|
||||||
@@ -329,7 +329,7 @@ class Cfg:
|
|||||||
# adding to global list
|
# adding to global list
|
||||||
self.dotfiles[dotfile.key] = dotfile
|
self.dotfiles[dotfile.key] = dotfile
|
||||||
|
|
||||||
return True
|
return True, dotfile
|
||||||
|
|
||||||
def get_dotfiles(self, profile):
|
def get_dotfiles(self, profile):
|
||||||
""" returns a list of dotfiles for a specific profile """
|
""" returns a list of dotfiles for a specific profile """
|
||||||
|
|||||||
@@ -232,21 +232,18 @@ def importer(opts, conf, paths):
|
|||||||
LOG.err('\"{}\" does not exist, ignored !'.format(path))
|
LOG.err('\"{}\" does not exist, ignored !'.format(path))
|
||||||
continue
|
continue
|
||||||
dst = path.rstrip(os.sep)
|
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
|
src = dst
|
||||||
if dst.startswith(home):
|
if dst.startswith(home):
|
||||||
src = dst[len(home):]
|
src = dst[len(home):]
|
||||||
src = src.lstrip('.' + os.sep)
|
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)
|
srcf = os.path.join(CUR, opts['dotpath'], src)
|
||||||
retconf = conf.new(dotfile, opts['profile'], opts['link'])
|
|
||||||
if not os.path.exists(srcf):
|
if not os.path.exists(srcf):
|
||||||
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))]
|
||||||
if opts['dry']:
|
if opts['dry']:
|
||||||
|
|||||||
Reference in New Issue
Block a user