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

improve migration to new format

This commit is contained in:
deadc0de6
2017-09-16 10:28:45 +02:00
parent f4a2ef97a7
commit 7b9c4d1692

View File

@@ -61,20 +61,18 @@ class Cfg:
self.log.err('missing \"%s\" in config' % (self.key_dotfiles))
return False
if self.content[self.key_profiles]:
one = list(self.content[self.key_profiles].keys())[0]
if self.key_profiles_dots not in \
self.content[self.key_profiles][one]:
self._migrate_conf()
return True
# make sure dotfiles are in a sub called "dotfiles"
pro = self.content[self.key_profiles]
tosave = False
for k in pro.keys():
if self.key_profiles_dots not in pro[k]:
pro[k] = {self.key_profiles_dots: pro[k]}
tosave = True
if tosave:
# save the new config file
self._save(self.content, self.cfgpath)
def _migrate_conf(self):
""" make sure dotfiles are in a sub
"dotfiles" entry in profiles (#12) """
new = {}
for k, v in self.content[self.key_profiles].items():
new[k] = {self.key_profiles_dots: v}
self.content[self.key_profiles] = new
self._save(self.content, self.cfgpath)
return True
def _parse_actions(self, actions, entries):
""" parse actions specified for an element """
@@ -166,6 +164,13 @@ class Cfg:
return absconf
return dotpath
def _save(self, content, path):
ret = False
with open(path, 'w') as f:
ret = yaml.dump(content, f,
default_flow_style=False, indent=2)
return ret
def new(self, dotfile, profile, link=False):
""" import new dotfile """
# keep it short
@@ -240,10 +245,3 @@ class Cfg:
# restore dotpath
self.configs[self.key_dotpath] = tmp
return ret
def _save(self, content, path):
ret = False
with open(path, 'w') as f:
ret = yaml.dump(content, f,
default_flow_style=False, indent=2)
return ret