mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 14:17:46 +00:00
Add TUTOR_VERSION to template variables
This commit is contained in:
parent
0199a1e916
commit
65dce18908
@ -11,6 +11,10 @@ class ConfigTests(unittest.TestCase):
|
|||||||
# This is necessary to avoid cached mocks
|
# This is necessary to avoid cached mocks
|
||||||
env.Renderer.reset()
|
env.Renderer.reset()
|
||||||
|
|
||||||
|
def test_version(self):
|
||||||
|
defaults = tutor_config.load_defaults()
|
||||||
|
self.assertNotIn("TUTOR_VERSION", defaults)
|
||||||
|
|
||||||
def test_merge(self):
|
def test_merge(self):
|
||||||
config = {}
|
config = {}
|
||||||
defaults = tutor_config.load_defaults()
|
defaults = tutor_config.load_defaults()
|
||||||
@ -39,16 +43,14 @@ class ConfigTests(unittest.TestCase):
|
|||||||
tutor_config.utils, "random_string"
|
tutor_config.utils, "random_string"
|
||||||
) as mock_random_string:
|
) as mock_random_string:
|
||||||
mock_random_string.return_value = "abcd"
|
mock_random_string.return_value = "abcd"
|
||||||
defaults = tutor_config.load_defaults()
|
config1, defaults = tutor_config.load_all(root)
|
||||||
config1 = tutor_config.load_current(root, defaults)
|
|
||||||
password1 = config1["MYSQL_ROOT_PASSWORD"]
|
password1 = config1["MYSQL_ROOT_PASSWORD"]
|
||||||
|
|
||||||
config1.pop("MYSQL_ROOT_PASSWORD")
|
config1.pop("MYSQL_ROOT_PASSWORD")
|
||||||
tutor_config.save_config(root, config1)
|
tutor_config.save_config(root, config1)
|
||||||
|
|
||||||
mock_random_string.return_value = "efgh"
|
mock_random_string.return_value = "efgh"
|
||||||
defaults = tutor_config.load_defaults()
|
config2, defaults = tutor_config.load_all(root)
|
||||||
config2 = tutor_config.load_current(root, defaults)
|
|
||||||
password2 = config2["MYSQL_ROOT_PASSWORD"]
|
password2 = config2["MYSQL_ROOT_PASSWORD"]
|
||||||
|
|
||||||
self.assertEqual("abcd", password1)
|
self.assertEqual("abcd", password1)
|
||||||
|
@ -39,3 +39,8 @@ class EnvTests(unittest.TestCase):
|
|||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.TutorError, env.render_file, {}, "local", "docker-compose.yml"
|
exceptions.TutorError, env.render_file, {}, "local", "docker-compose.yml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_render_full(self):
|
||||||
|
with tempfile.TemporaryDirectory() as root:
|
||||||
|
defaults = tutor_config.load_defaults()
|
||||||
|
env.render_full(root, defaults)
|
||||||
|
@ -33,8 +33,7 @@ def save_command(root, silent1, silent2, set_):
|
|||||||
|
|
||||||
def save(root, silent=False, keyvalues=None):
|
def save(root, silent=False, keyvalues=None):
|
||||||
keyvalues = keyvalues or []
|
keyvalues = keyvalues or []
|
||||||
defaults = load_defaults()
|
config, defaults = load_all(root)
|
||||||
config = load_current(root, defaults)
|
|
||||||
for k, v in keyvalues:
|
for k, v in keyvalues:
|
||||||
config[k] = v
|
config[k] = v
|
||||||
if not silent:
|
if not silent:
|
||||||
@ -54,8 +53,7 @@ def printroot(root):
|
|||||||
@opts.root
|
@opts.root
|
||||||
@click.argument("key")
|
@click.argument("key")
|
||||||
def printvalue(root, key):
|
def printvalue(root, key):
|
||||||
defaults = load_defaults()
|
config, defaults = load_all(root)
|
||||||
config = load_current(root, defaults)
|
|
||||||
merge(config, defaults)
|
merge(config, defaults)
|
||||||
try:
|
try:
|
||||||
fmt.echo(config[key])
|
fmt.echo(config[key])
|
||||||
@ -132,6 +130,16 @@ def pre_upgrade_announcement(root):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def load_all(root):
|
||||||
|
defaults = load_defaults()
|
||||||
|
current = load_current(root, defaults)
|
||||||
|
return current, defaults
|
||||||
|
|
||||||
|
|
||||||
|
def load_defaults():
|
||||||
|
return serialize.load(env.read("config.yml"))
|
||||||
|
|
||||||
|
|
||||||
def load_current(root, defaults):
|
def load_current(root, defaults):
|
||||||
convert_json2yml(root)
|
convert_json2yml(root)
|
||||||
config = load_user(root)
|
config = load_user(root)
|
||||||
@ -308,10 +316,6 @@ def load_interactive(config, defaults):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_defaults():
|
|
||||||
return serialize.load(env.read("config.yml"))
|
|
||||||
|
|
||||||
|
|
||||||
def ask(question, key, config, defaults):
|
def ask(question, key, config, defaults):
|
||||||
default = env.render_str(config, config.get(key, defaults[key]))
|
default = env.render_str(config, config.get(key, defaults[key]))
|
||||||
config[key] = click.prompt(
|
config[key] = click.prompt(
|
||||||
|
@ -27,6 +27,7 @@ class Renderer:
|
|||||||
environment.filters["random_string"] = utils.random_string
|
environment.filters["random_string"] = utils.random_string
|
||||||
environment.filters["common_domain"] = utils.random_string
|
environment.filters["common_domain"] = utils.random_string
|
||||||
environment.filters["reverse_host"] = utils.reverse_host
|
environment.filters["reverse_host"] = utils.reverse_host
|
||||||
|
environment.globals["TUTOR_VERSION"] = __version__
|
||||||
cls.ENVIRONMENT = environment
|
cls.ENVIRONMENT = environment
|
||||||
|
|
||||||
return cls.ENVIRONMENT
|
return cls.ENVIRONMENT
|
||||||
@ -69,8 +70,7 @@ def render_full(root, config):
|
|||||||
for subdir in ["android", "apps", "k8s", "local", "webui"]:
|
for subdir in ["android", "apps", "k8s", "local", "webui"]:
|
||||||
render_subdir(subdir, root, config)
|
render_subdir(subdir, root, config)
|
||||||
copy_subdir("build", root)
|
copy_subdir("build", root)
|
||||||
with open(pathjoin(root, VERSION_FILENAME), "w") as f:
|
render_file(config, VERSION_FILENAME)
|
||||||
f.write(__version__)
|
|
||||||
|
|
||||||
|
|
||||||
def render_subdir(subdir, root, config):
|
def render_subdir(subdir, root, config):
|
||||||
|
1
tutor/templates/version
Normal file
1
tutor/templates/version
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{ TUTOR_VERSION }}
|
Loading…
Reference in New Issue
Block a user