From 45f29679b277246485e19957e8015f6f3be21296 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 2 Feb 2019 19:20:33 +0100 Subject: [PATCH] add profile to all other variables --- dotdrop/config.py | 6 ++++-- dotdrop/dotdrop.py | 8 ++++---- dotdrop/templategen.py | 4 +--- tests/test_compare.py | 2 +- tests/test_install.py | 5 +++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dotdrop/config.py b/dotdrop/config.py index dbd59e2..ff3412e 100644 --- a/dotdrop/config.py +++ b/dotdrop/config.py @@ -120,8 +120,7 @@ class Cfg: def eval_dotfiles(self, profile, debug=False): """resolve dotfiles src/dst templating""" - t = Templategen(profile=profile, - variables=self.get_variables(profile), + t = Templategen(variables=self.get_variables(profile), debug=debug) for d in self.get_dotfiles(profile): d.src = t.generate_string(d.src) @@ -627,6 +626,9 @@ class Cfg: """return the variables for this profile""" variables = {} + # profile variable + variables['profile'] = profile + # global variables if self.key_variables in self.content: variables.update(self.content[self.key_variables]) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index b974be9..a040e10 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -89,8 +89,8 @@ def cmd_install(opts, conf, temporary=False, keys=[]): LOG.warn(msg.format(opts['profile'])) return False - t = Templategen(profile=opts['profile'], base=opts['dotpath'], - variables=opts['variables'], debug=opts['debug']) + t = Templategen(base=opts['dotpath'], variables=opts['variables'], + debug=opts['debug']) tmpdir = None if temporary: tmpdir = get_tmpdir() @@ -160,8 +160,8 @@ def cmd_compare(opts, conf, tmp, focus=[], ignore=[]): if len(selected) < 1: return False - t = Templategen(profile=opts['profile'], base=opts['dotpath'], - variables=opts['variables'], debug=opts['debug']) + t = Templategen(base=opts['dotpath'], variables=opts['variables'], + debug=opts['debug']) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], workdir=opts['workdir'], debug=opts['debug']) diff --git a/dotdrop/templategen.py b/dotdrop/templategen.py index 6b7c8e9..63d3f1e 100644 --- a/dotdrop/templategen.py +++ b/dotdrop/templategen.py @@ -23,7 +23,7 @@ COMMENT_END = '@@#}' class Templategen: - def __init__(self, profile='', base='.', variables={}, debug=False): + def __init__(self, base='.', variables={}, debug=False): self.base = base.rstrip(os.sep) self.debug = debug self.log = Logger() @@ -39,8 +39,6 @@ class Templategen: comment_end_string=COMMENT_END) # adding variables self.env.globals['env'] = os.environ - if profile: - self.env.globals['profile'] = profile self.env.globals.update(variables) # adding header method self.env.globals['header'] = self._header diff --git a/tests/test_compare.py b/tests/test_compare.py index 9003a7e..a236282 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -29,7 +29,7 @@ class TestCompare(unittest.TestCase): def compare(self, opts, conf, tmp, nbdotfiles): dotfiles = conf.get_dotfiles(opts['profile']) self.assertTrue(len(dotfiles) == nbdotfiles) - t = Templategen(opts['profile'], base=opts['dotpath'], debug=True) + t = Templategen(base=opts['dotpath'], debug=True) inst = Installer(create=opts['create'], backup=opts['backup'], dry=opts['dry'], base=opts['dotpath'], debug=True) comp = Comparator() diff --git a/tests/test_install.py b/tests/test_install.py index 11a57d0..fee14c3 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -17,6 +17,7 @@ from dotdrop.installer import Installer from dotdrop.action import Action from dotdrop.dotdrop import cmd_install from dotdrop.linktypes import LinkTypes +from dotdrop.utils import header class TestInstall(unittest.TestCase): @@ -163,7 +164,7 @@ exec bspwm d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr) # to test template - f10, _ = create_random_file(tmp, content='{{@@ profile @@}}') + f10, _ = create_random_file(tmp, content='{{@@ header() @@}}') dst10 = os.path.join(dst, get_string(6)) d10 = Dotfile(get_string(6), dst10, os.path.basename(f10)) @@ -226,7 +227,7 @@ exec bspwm # test template has been remplaced self.assertTrue(os.path.exists(dst10)) tempcontent = open(dst10, 'r').read().rstrip() - self.assertTrue(tempcontent == profile) + self.assertTrue(tempcontent == header()) def test_link_children(self):