1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 05:39:43 +00:00

add ability to import to no profile with ALL

This commit is contained in:
deadc0de6
2022-09-03 08:44:47 +02:00
committed by deadc0de
parent 2ed28ceeda
commit 7974939e68
5 changed files with 180 additions and 15 deletions

View File

@@ -88,13 +88,15 @@ class CfgAggregator:
if not dotfile:
return False
ret = dotfile is not None
# add to profile
key = dotfile.key
ret = self.cfgyaml.add_dotfile_to_profile(key, self.profile_key)
if ret:
msg = f'new dotfile {key} to profile {self.profile_key}'
self.log.dbg(msg)
if self.profile_key != self.cfgyaml.key_all:
# add to profile
key = dotfile.key
ret = self.cfgyaml.add_dotfile_to_profile(key, self.profile_key)
if ret:
msg = f'new dotfile {key} to profile {self.profile_key}'
self.log.dbg(msg)
# save the config and reload it
if ret:
@@ -141,15 +143,18 @@ class CfgAggregator:
@src: dotfile src (in dotpath)
@dst: dotfile dst (on filesystem)
"""
try:
src = self.cfgyaml.resolve_dotfile_src(src)
except UndefinedException as exc:
err = f'unable to resolve {src}: {exc}'
self.log.err(err)
return None
if not os.path.isabs(src):
# ensures we have an absolute path
try:
src = self.cfgyaml.resolve_dotfile_src(src)
except UndefinedException as exc:
err = f'unable to resolve {src}: {exc}'
self.log.err(err)
return None
dotfiles = self.get_dotfile_by_dst(dst)
for dotfile in dotfiles:
if dotfile.src == src:
dsrc = self.cfgyaml.resolve_dotfile_src(dotfile.src)
if dsrc == src:
return dotfile
return None
@@ -196,7 +201,13 @@ class CfgAggregator:
return res
def get_dotfiles(self, profile_key=None):
"""get all dotfiles for this profile or specified profile key"""
"""
get all dotfiles for the current profile if None
or the specified profile_key if defined
or all dotfiles if profile_key is ALL
"""
if profile_key == self.cfgyaml.key_all:
return self.dotfiles
dotfiles = []
profile = self.get_profile(key=profile_key)
if not profile:

View File

@@ -351,6 +351,8 @@ class CfgYaml:
"""
# create the profile if it doesn't exist
self._new_profile(profile_key)
if profile_key not in self.profiles:
return False
profile = self.profiles[profile_key]
# ensure profile dotfiles list is not None
@@ -724,6 +726,14 @@ class CfgYaml:
return profiles
new = {}
for k, val in profiles.items():
if k == self.key_all:
msg = f'\"{self.key_all}\" is a special profile name, '
msg += 'consider renaming to avoid any issue.'
self._log.warn(msg)
if not k:
msg = 'empty profile name'
self._log.warn(msg)
continue
if not val:
# no dotfiles
continue
@@ -1097,6 +1107,14 @@ class CfgYaml:
def _new_profile(self, key):
"""add a new profile if it doesn't exist"""
if key == self.key_all:
err = f'profile key \"{key}\" is reserved'
self._log.warn(err)
raise YamlException(err)
if not key:
err = 'empty profile key'
self._log.warn(err)
raise YamlException(err)
if key not in self.profiles.keys():
# update yaml_dict
self._yaml_dict[self.key_profiles][key] = {