mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 13:44:16 +00:00
improve migration to new format
This commit is contained in:
@@ -61,20 +61,18 @@ class Cfg:
|
|||||||
self.log.err('missing \"%s\" in config' % (self.key_dotfiles))
|
self.log.err('missing \"%s\" in config' % (self.key_dotfiles))
|
||||||
return False
|
return False
|
||||||
if self.content[self.key_profiles]:
|
if self.content[self.key_profiles]:
|
||||||
one = list(self.content[self.key_profiles].keys())[0]
|
# make sure dotfiles are in a sub called "dotfiles"
|
||||||
if self.key_profiles_dots not in \
|
pro = self.content[self.key_profiles]
|
||||||
self.content[self.key_profiles][one]:
|
tosave = False
|
||||||
self._migrate_conf()
|
for k in pro.keys():
|
||||||
return True
|
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):
|
return True
|
||||||
""" 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)
|
|
||||||
|
|
||||||
def _parse_actions(self, actions, entries):
|
def _parse_actions(self, actions, entries):
|
||||||
""" parse actions specified for an element """
|
""" parse actions specified for an element """
|
||||||
@@ -166,6 +164,13 @@ class Cfg:
|
|||||||
return absconf
|
return absconf
|
||||||
return dotpath
|
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):
|
def new(self, dotfile, profile, link=False):
|
||||||
""" import new dotfile """
|
""" import new dotfile """
|
||||||
# keep it short
|
# keep it short
|
||||||
@@ -240,10 +245,3 @@ class Cfg:
|
|||||||
# restore dotpath
|
# restore dotpath
|
||||||
self.configs[self.key_dotpath] = tmp
|
self.configs[self.key_dotpath] = tmp
|
||||||
return ret
|
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user