1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 01:18:59 +00:00

add profile to all other variables

This commit is contained in:
deadc0de6
2019-02-02 19:20:33 +01:00
parent e67df9f648
commit 45f29679b2
5 changed files with 13 additions and 12 deletions

View File

@@ -120,8 +120,7 @@ class Cfg:
def eval_dotfiles(self, profile, debug=False): def eval_dotfiles(self, profile, debug=False):
"""resolve dotfiles src/dst templating""" """resolve dotfiles src/dst templating"""
t = Templategen(profile=profile, t = Templategen(variables=self.get_variables(profile),
variables=self.get_variables(profile),
debug=debug) debug=debug)
for d in self.get_dotfiles(profile): for d in self.get_dotfiles(profile):
d.src = t.generate_string(d.src) d.src = t.generate_string(d.src)
@@ -627,6 +626,9 @@ class Cfg:
"""return the variables for this profile""" """return the variables for this profile"""
variables = {} variables = {}
# profile variable
variables['profile'] = profile
# global variables # global variables
if self.key_variables in self.content: if self.key_variables in self.content:
variables.update(self.content[self.key_variables]) variables.update(self.content[self.key_variables])

View File

@@ -89,8 +89,8 @@ def cmd_install(opts, conf, temporary=False, keys=[]):
LOG.warn(msg.format(opts['profile'])) LOG.warn(msg.format(opts['profile']))
return False return False
t = Templategen(profile=opts['profile'], base=opts['dotpath'], t = Templategen(base=opts['dotpath'], variables=opts['variables'],
variables=opts['variables'], debug=opts['debug']) debug=opts['debug'])
tmpdir = None tmpdir = None
if temporary: if temporary:
tmpdir = get_tmpdir() tmpdir = get_tmpdir()
@@ -160,8 +160,8 @@ def cmd_compare(opts, conf, tmp, focus=[], ignore=[]):
if len(selected) < 1: if len(selected) < 1:
return False return False
t = Templategen(profile=opts['profile'], base=opts['dotpath'], t = Templategen(base=opts['dotpath'], variables=opts['variables'],
variables=opts['variables'], debug=opts['debug']) debug=opts['debug'])
inst = Installer(create=opts['create'], backup=opts['backup'], inst = Installer(create=opts['create'], backup=opts['backup'],
dry=opts['dry'], base=opts['dotpath'], dry=opts['dry'], base=opts['dotpath'],
workdir=opts['workdir'], debug=opts['debug']) workdir=opts['workdir'], debug=opts['debug'])

View File

@@ -23,7 +23,7 @@ COMMENT_END = '@@#}'
class Templategen: class Templategen:
def __init__(self, profile='', base='.', variables={}, debug=False): def __init__(self, base='.', variables={}, debug=False):
self.base = base.rstrip(os.sep) self.base = base.rstrip(os.sep)
self.debug = debug self.debug = debug
self.log = Logger() self.log = Logger()
@@ -39,8 +39,6 @@ class Templategen:
comment_end_string=COMMENT_END) comment_end_string=COMMENT_END)
# adding variables # adding variables
self.env.globals['env'] = os.environ self.env.globals['env'] = os.environ
if profile:
self.env.globals['profile'] = profile
self.env.globals.update(variables) self.env.globals.update(variables)
# adding header method # adding header method
self.env.globals['header'] = self._header self.env.globals['header'] = self._header

View File

@@ -29,7 +29,7 @@ class TestCompare(unittest.TestCase):
def compare(self, opts, conf, tmp, nbdotfiles): def compare(self, opts, conf, tmp, nbdotfiles):
dotfiles = conf.get_dotfiles(opts['profile']) dotfiles = conf.get_dotfiles(opts['profile'])
self.assertTrue(len(dotfiles) == nbdotfiles) 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'], inst = Installer(create=opts['create'], backup=opts['backup'],
dry=opts['dry'], base=opts['dotpath'], debug=True) dry=opts['dry'], base=opts['dotpath'], debug=True)
comp = Comparator() comp = Comparator()

View File

@@ -17,6 +17,7 @@ from dotdrop.installer import Installer
from dotdrop.action import Action from dotdrop.action import Action
from dotdrop.dotdrop import cmd_install from dotdrop.dotdrop import cmd_install
from dotdrop.linktypes import LinkTypes from dotdrop.linktypes import LinkTypes
from dotdrop.utils import header
class TestInstall(unittest.TestCase): class TestInstall(unittest.TestCase):
@@ -163,7 +164,7 @@ exec bspwm
d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr) d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=tr)
# to test template # 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)) dst10 = os.path.join(dst, get_string(6))
d10 = Dotfile(get_string(6), dst10, os.path.basename(f10)) d10 = Dotfile(get_string(6), dst10, os.path.basename(f10))
@@ -226,7 +227,7 @@ exec bspwm
# test template has been remplaced # test template has been remplaced
self.assertTrue(os.path.exists(dst10)) self.assertTrue(os.path.exists(dst10))
tempcontent = open(dst10, 'r').read().rstrip() tempcontent = open(dst10, 'r').read().rstrip()
self.assertTrue(tempcontent == profile) self.assertTrue(tempcontent == header())
def test_link_children(self): def test_link_children(self):