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

fix dynvariables being executed twice (#83)

This commit is contained in:
deadc0de6
2019-02-04 21:39:00 +01:00
parent 5798c78309
commit 9d081957fc
3 changed files with 9 additions and 8 deletions

View File

@@ -118,9 +118,9 @@ class Cfg:
if not self._load_file(): if not self._load_file():
raise ValueError('config is not valid') raise ValueError('config is not valid')
def eval_dotfiles(self, profile, debug=False): def eval_dotfiles(self, profile, variables, debug=False):
"""resolve dotfiles src/dst/actions templating for this profile""" """resolve dotfiles src/dst/actions templating for this profile"""
t = Templategen(variables=self.get_variables(profile, debug=debug)) t = Templategen(variables=variables)
for d in self.get_dotfiles(profile): for d in self.get_dotfiles(profile):
# src and dst path # src and dst path
d.src = t.generate_string(d.src) d.src = t.generate_string(d.src)

View File

@@ -218,8 +218,8 @@ def cmd_update(opts, conf, paths, iskey=False, ignore=[], showpatch=False):
"""update the dotfile(s) from path(s) or key(s)""" """update the dotfile(s) from path(s) or key(s)"""
ret = True ret = True
updater = Updater(conf, opts['dotpath'], opts['profile'], updater = Updater(conf, opts['dotpath'], opts['profile'],
opts['dry'], opts['safe'], iskey=iskey, opts['variables'], opts['dry'], opts['safe'],
debug=opts['debug'], ignore=[], iskey=iskey, debug=opts['debug'], ignore=[],
showpatch=showpatch) showpatch=showpatch)
if not iskey: if not iskey:
# update paths # update paths
@@ -461,7 +461,8 @@ def main():
LOG.dbg('configs:\n{}'.format(conf.dump())) LOG.dbg('configs:\n{}'.format(conf.dump()))
# resolve dynamic paths # resolve dynamic paths
conf.eval_dotfiles(opts['profile'], debug=opts['debug']) conf.eval_dotfiles(opts['profile'], opts['variables'],
debug=opts['debug'])
if ENV_NOBANNER not in os.environ \ if ENV_NOBANNER not in os.environ \
and opts['banner'] \ and opts['banner'] \

View File

@@ -20,11 +20,12 @@ TILD = '~'
class Updater: class Updater:
def __init__(self, conf, dotpath, profile, dry, safe, def __init__(self, conf, dotpath, profile, variables, dry, safe,
iskey=False, debug=False, ignore=[], showpatch=False): iskey=False, debug=False, ignore=[], showpatch=False):
self.conf = conf self.conf = conf
self.dotpath = dotpath self.dotpath = dotpath
self.profile = profile self.profile = profile
self.variables = variables
self.dry = dry self.dry = dry
self.safe = safe self.safe = safe
self.iskey = iskey self.iskey = iskey
@@ -155,8 +156,7 @@ class Updater:
def _resolve_template(self, tpath): def _resolve_template(self, tpath):
"""resolve the template to a temporary file""" """resolve the template to a temporary file"""
variables = self.conf.get_variables(self.profile) t = Templategen(variables=self.variables, base=self.dotpath,
t = Templategen(variables=variables, base=self.dotpath,
debug=self.debug) debug=self.debug)
return t.generate(tpath) return t.generate(tpath)