diff --git a/test/test_unit_template_default.py b/test/test_unit_template_default.py index 3c071c5..a4532c2 100644 --- a/test/test_unit_template_default.py +++ b/test/test_unit_template_default.py @@ -141,7 +141,7 @@ end of template INCLUDE_BASIC = "basic\n" INCLUDE_VARIABLES = """\ -included <{{ yadm.class }}> file +included <{{ yadm.class }}> file ({{yadm.filename}}) empty line above """ @@ -151,8 +151,8 @@ TEMPLATE_INCLUDE = """\ The first line {% include empty %} An empty file removes the line above -{%include basic%} -{% include "./variables.{{ yadm.os }}" %} +{%include ./basic%} +{% include "variables.{{ yadm.os }}" %} {% include dir/nested %} Include basic again: {% include basic %} @@ -161,7 +161,7 @@ EXPECTED_INCLUDE = f"""\ The first line An empty file removes the line above basic -included <{LOCAL_CLASS}> file +included <{LOCAL_CLASS}> file (VARIABLES_FILENAME) empty line above no newline at the end @@ -280,6 +280,8 @@ def test_include(runner, yadm, tmpdir): input_file.chmod(FILE_MODE) output_file = tmpdir.join("output") + expected = EXPECTED_INCLUDE.replace("VARIABLES_FILENAME", str(variables_file)) + script = f""" YADM_TEST=1 source {yadm} set_awk @@ -290,7 +292,7 @@ def test_include(runner, yadm, tmpdir): run = runner(command=["bash"], inp=script) assert run.success assert run.err == "" - assert output_file.read() == EXPECTED_INCLUDE + assert output_file.read() == expected assert os.stat(output_file).st_mode == os.stat(input_file).st_mode diff --git a/yadm b/yadm index c239f65..473a7b1 100755 --- a/yadm +++ b/yadm @@ -379,7 +379,7 @@ BEGIN { yadm["user"] = user yadm["distro"] = distro yadm["distro_family"] = distro_family - yadm["source"] = source + yadm["source"] = ARGV[1] VARIABLE = "(env|yadm)\\.[a-zA-Z0-9_]+" @@ -469,6 +469,9 @@ function replace_vars(input) { if (fields[1] == "env") { output = output ENVIRON[fields[2]] } + else if (fields[2] == "filename") { + output = output filename[current] + } else { output = output yadm[fields[2]] } @@ -485,7 +488,6 @@ EOF -v user="$local_user" \ -v distro="$local_distro" \ -v distro_family="$local_distro_family" \ - -v source="$input" \ -v source_dir="$(builtin_dirname "$input")" \ "$awk_pgm" \ "$input" "${local_classes[@]}" diff --git a/yadm.1 b/yadm.1 index 9145b24..eb68337 100644 --- a/yadm.1 +++ b/yadm.1 @@ -705,6 +705,7 @@ During processing, the following variables are available in the template: yadm.classes YADM_CLASSES All classes yadm.distro YADM_DISTRO lsb_release \-si yadm.distro_family YADM_DISTRO_FAMILY ID_LIKE from /etc/os-release + yadm.filename Filename for the current file yadm.hostname YADM_HOSTNAME uname \-n (without domain) yadm.os YADM_OS uname \-s yadm.source YADM_SOURCE Template filename