mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 23:39:16 +00:00
fix duplicate key bug and add more verbosity
This commit is contained in:
@@ -421,12 +421,13 @@ class Cfg:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _norm_key_elem(self, elem):
|
def _norm_key_elem(self, elem):
|
||||||
"""normalize key element for sanity"""
|
"""normalize path element for sanity"""
|
||||||
elem = elem.lstrip('.')
|
elem = elem.lstrip('.')
|
||||||
elem = elem.replace(' ', '-')
|
elem = elem.replace(' ', '-')
|
||||||
return elem.lower()
|
return elem.lower()
|
||||||
|
|
||||||
def _get_paths(self, path):
|
def _get_paths(self, path):
|
||||||
|
"""return a list of path elements, excluded home path"""
|
||||||
p = strip_home(path)
|
p = strip_home(path)
|
||||||
dirs = []
|
dirs = []
|
||||||
while True:
|
while True:
|
||||||
@@ -466,7 +467,14 @@ class Cfg:
|
|||||||
key = '_'.join(entries)
|
key = '_'.join(entries)
|
||||||
key = '{}_{}'.format(pre, key)
|
key = '{}_{}'.format(pre, key)
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
break
|
return key
|
||||||
|
okey = key
|
||||||
|
cnt = 1
|
||||||
|
while key in keys:
|
||||||
|
# if unable to get a unique path
|
||||||
|
# get a random one
|
||||||
|
key = '{}_{}'.format(okey, cnt)
|
||||||
|
cnt += 1
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def short_to_long(self):
|
def short_to_long(self):
|
||||||
@@ -506,12 +514,13 @@ class Cfg:
|
|||||||
dsts = [(k, d.dst) for k, d in self.dotfiles.items()]
|
dsts = [(k, d.dst) for k, d in self.dotfiles.items()]
|
||||||
if dotfile.dst in [x[1] for x in dsts]:
|
if dotfile.dst in [x[1] for x in dsts]:
|
||||||
return True, [x[0] for x in dsts if x[1] == dotfile.dst][0]
|
return True, [x[0] for x in dsts if x[1] == dotfile.dst][0]
|
||||||
|
# return key for this new dotfile
|
||||||
path = os.path.expanduser(dotfile.dst)
|
path = os.path.expanduser(dotfile.dst)
|
||||||
if self.lnk_settings[self.key_long]:
|
if self.lnk_settings[self.key_long]:
|
||||||
return False, self._get_long_key(path)
|
return False, self._get_long_key(path)
|
||||||
return False, self._get_short_key(path, self.dotfiles.keys())
|
return False, self._get_short_key(path, self.dotfiles.keys())
|
||||||
|
|
||||||
def new(self, dotfile, profile, link=False):
|
def new(self, dotfile, profile, link=False, debug=False):
|
||||||
"""import new dotfile
|
"""import new dotfile
|
||||||
dotfile key will change and can be empty"""
|
dotfile key will change and can be empty"""
|
||||||
# keep it short
|
# keep it short
|
||||||
@@ -520,6 +529,8 @@ class Cfg:
|
|||||||
|
|
||||||
# adding new profile if doesn't exist
|
# adding new profile if doesn't exist
|
||||||
if profile not in self.lnk_profiles:
|
if profile not in self.lnk_profiles:
|
||||||
|
if debug:
|
||||||
|
self.log.dbg('adding profile to config')
|
||||||
# in the yaml
|
# in the yaml
|
||||||
self.lnk_profiles[profile] = {self.key_profiles_dots: []}
|
self.lnk_profiles[profile] = {self.key_profiles_dots: []}
|
||||||
# in the global list of dotfiles per profile
|
# in the global list of dotfiles per profile
|
||||||
@@ -527,6 +538,8 @@ class Cfg:
|
|||||||
|
|
||||||
exists, key = self._dotfile_exists(dotfile)
|
exists, key = self._dotfile_exists(dotfile)
|
||||||
if exists:
|
if exists:
|
||||||
|
if debug:
|
||||||
|
self.log.dbg('key already exists: {}'.format(key))
|
||||||
# when dotfile already there somewhere
|
# when dotfile already there somewhere
|
||||||
dotfile = self.dotfiles[key]
|
dotfile = self.dotfiles[key]
|
||||||
if dotfile in self.prodots[profile]:
|
if dotfile in self.prodots[profile]:
|
||||||
@@ -543,8 +556,12 @@ class Cfg:
|
|||||||
pro[self.key_profiles_dots].append(dotfile.key)
|
pro[self.key_profiles_dots].append(dotfile.key)
|
||||||
return True, dotfile
|
return True, dotfile
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
self.log.dbg('dotfile attributed key: {}'.format(key))
|
||||||
# adding the new dotfile
|
# adding the new dotfile
|
||||||
dotfile.key = key
|
dotfile.key = key
|
||||||
|
if debug:
|
||||||
|
self.log.dbg('adding new dotfile: {}'.format(dotfile))
|
||||||
# add the entry in the yaml file
|
# add the entry in the yaml file
|
||||||
dots = self.content[self.key_dotfiles]
|
dots = self.content[self.key_dotfiles]
|
||||||
dots[dotfile.key] = {
|
dots[dotfile.key] = {
|
||||||
|
|||||||
@@ -235,6 +235,8 @@ def cmd_importer(opts, conf, paths):
|
|||||||
ret = True
|
ret = True
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
if opts['debug']:
|
||||||
|
LOG.dbg('trying to import {}'.format(path))
|
||||||
if not os.path.lexists(path):
|
if not os.path.lexists(path):
|
||||||
LOG.err('\"{}\" does not exist, ignored!'.format(path))
|
LOG.err('\"{}\" does not exist, ignored!'.format(path))
|
||||||
ret = False
|
ret = False
|
||||||
@@ -250,6 +252,8 @@ def cmd_importer(opts, conf, paths):
|
|||||||
# create a new dotfile
|
# create a new dotfile
|
||||||
dotfile = Dotfile('', dst, src)
|
dotfile = Dotfile('', dst, src)
|
||||||
linkit = opts['link'] or opts['link_by_default']
|
linkit = opts['link'] or opts['link_by_default']
|
||||||
|
if opts['debug']:
|
||||||
|
LOG.dbg('new dotfile: {}'.format(dotfile))
|
||||||
|
|
||||||
# prepare hierarchy for dotfile
|
# prepare hierarchy for dotfile
|
||||||
srcf = os.path.join(opts['dotpath'], src)
|
srcf = os.path.join(opts['dotpath'], src)
|
||||||
@@ -277,7 +281,8 @@ def cmd_importer(opts, conf, paths):
|
|||||||
if linkit:
|
if linkit:
|
||||||
remove(dst)
|
remove(dst)
|
||||||
os.symlink(srcf, dst)
|
os.symlink(srcf, dst)
|
||||||
retconf, dotfile = conf.new(dotfile, opts['profile'], linkit)
|
retconf, dotfile = conf.new(dotfile, opts['profile'],
|
||||||
|
linkit, debug=opts['debug'])
|
||||||
if retconf:
|
if retconf:
|
||||||
LOG.sub('\"{}\" imported'.format(path))
|
LOG.sub('\"{}\" imported'.format(path))
|
||||||
cnt += 1
|
cnt += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user