mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 06:07:56 +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
|
||||
env.Renderer.reset()
|
||||
|
||||
def test_version(self):
|
||||
defaults = tutor_config.load_defaults()
|
||||
self.assertNotIn("TUTOR_VERSION", defaults)
|
||||
|
||||
def test_merge(self):
|
||||
config = {}
|
||||
defaults = tutor_config.load_defaults()
|
||||
@ -39,16 +43,14 @@ class ConfigTests(unittest.TestCase):
|
||||
tutor_config.utils, "random_string"
|
||||
) as mock_random_string:
|
||||
mock_random_string.return_value = "abcd"
|
||||
defaults = tutor_config.load_defaults()
|
||||
config1 = tutor_config.load_current(root, defaults)
|
||||
config1, defaults = tutor_config.load_all(root)
|
||||
password1 = config1["MYSQL_ROOT_PASSWORD"]
|
||||
|
||||
config1.pop("MYSQL_ROOT_PASSWORD")
|
||||
tutor_config.save_config(root, config1)
|
||||
|
||||
mock_random_string.return_value = "efgh"
|
||||
defaults = tutor_config.load_defaults()
|
||||
config2 = tutor_config.load_current(root, defaults)
|
||||
config2, defaults = tutor_config.load_all(root)
|
||||
password2 = config2["MYSQL_ROOT_PASSWORD"]
|
||||
|
||||
self.assertEqual("abcd", password1)
|
||||
|
@ -39,3 +39,8 @@ class EnvTests(unittest.TestCase):
|
||||
self.assertRaises(
|
||||
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):
|
||||
keyvalues = keyvalues or []
|
||||
defaults = load_defaults()
|
||||
config = load_current(root, defaults)
|
||||
config, defaults = load_all(root)
|
||||
for k, v in keyvalues:
|
||||
config[k] = v
|
||||
if not silent:
|
||||
@ -54,8 +53,7 @@ def printroot(root):
|
||||
@opts.root
|
||||
@click.argument("key")
|
||||
def printvalue(root, key):
|
||||
defaults = load_defaults()
|
||||
config = load_current(root, defaults)
|
||||
config, defaults = load_all(root)
|
||||
merge(config, defaults)
|
||||
try:
|
||||
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):
|
||||
convert_json2yml(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):
|
||||
default = env.render_str(config, config.get(key, defaults[key]))
|
||||
config[key] = click.prompt(
|
||||
|
@ -27,6 +27,7 @@ class Renderer:
|
||||
environment.filters["random_string"] = utils.random_string
|
||||
environment.filters["common_domain"] = utils.random_string
|
||||
environment.filters["reverse_host"] = utils.reverse_host
|
||||
environment.globals["TUTOR_VERSION"] = __version__
|
||||
cls.ENVIRONMENT = environment
|
||||
|
||||
return cls.ENVIRONMENT
|
||||
@ -69,8 +70,7 @@ def render_full(root, config):
|
||||
for subdir in ["android", "apps", "k8s", "local", "webui"]:
|
||||
render_subdir(subdir, root, config)
|
||||
copy_subdir("build", root)
|
||||
with open(pathjoin(root, VERSION_FILENAME), "w") as f:
|
||||
f.write(__version__)
|
||||
render_file(config, VERSION_FILENAME)
|
||||
|
||||
|
||||
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