From 9d081957fc4d82f7659d5c3cd5145898fa057e99 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Mon, 4 Feb 2019 21:39:00 +0100 Subject: [PATCH] fix dynvariables being executed twice (#83) --- dotdrop/config.py | 4 ++-- dotdrop/dotdrop.py | 7 ++++--- dotdrop/updater.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dotdrop/config.py b/dotdrop/config.py index f337946..be71463 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -118,9 +118,9 @@ class Cfg: if not self._load_file(): 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""" - t = Templategen(variables=self.get_variables(profile, debug=debug)) + t = Templategen(variables=variables) for d in self.get_dotfiles(profile): # src and dst path d.src = t.generate_string(d.src) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index ecd124f..df0c79e 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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)""" ret = True updater = Updater(conf, opts['dotpath'], opts['profile'], - opts['dry'], opts['safe'], iskey=iskey, - debug=opts['debug'], ignore=[], + opts['variables'], opts['dry'], opts['safe'], + iskey=iskey, debug=opts['debug'], ignore=[], showpatch=showpatch) if not iskey: # update paths @@ -461,7 +461,8 @@ def main(): LOG.dbg('configs:\n{}'.format(conf.dump())) # 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 \ and opts['banner'] \ diff --git a/dotdrop/updater.py b/dotdrop/updater.py index 27e7f84..1577841 100644 --- a/dotdrop/updater.py +++ b/dotdrop/updater.py @@ -20,11 +20,12 @@ TILD = '~' 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): self.conf = conf self.dotpath = dotpath self.profile = profile + self.variables = variables self.dry = dry self.safe = safe self.iskey = iskey @@ -155,8 +156,7 @@ class Updater: def _resolve_template(self, tpath): """resolve the template to a temporary file""" - variables = self.conf.get_variables(self.profile) - t = Templategen(variables=variables, base=self.dotpath, + t = Templategen(variables=self.variables, base=self.dotpath, debug=self.debug) return t.generate(tpath)