1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Ignore case in alt and default template processor conditions

This aligns all conditions with distro and distro_family.

Suggestion from #456.
This commit is contained in:
Erik Flodin
2024-12-09 23:50:49 +01:00
parent 6c1970fb41
commit c092b7c099
4 changed files with 41 additions and 43 deletions

View File

@@ -54,37 +54,37 @@ def calculate_score(filename):
if label in CONDITION["default"]["labels"]:
score += 1000
elif label in CONDITION["arch"]["labels"]:
if value == "testarch":
if value.lower() == "testarch":
score += 1000 + CONDITION["arch"]["modifier"]
else:
score = 0
break
elif label in CONDITION["system"]["labels"]:
if value == "testsystem":
if value.lower() == "testsystem":
score += 1000 + CONDITION["system"]["modifier"]
else:
score = 0
break
elif label in CONDITION["distro"]["labels"]:
if value == "testdistro":
if value.lower() == "testdistro":
score += 1000 + CONDITION["distro"]["modifier"]
else:
score = 0
break
elif label in CONDITION["class"]["labels"]:
if value == "testclass":
if value.lower() == "testclass":
score += 1000 + CONDITION["class"]["modifier"]
else:
score = 0
break
elif label in CONDITION["hostname"]["labels"]:
if value == "testhost":
if value.lower() == "testhost":
score += 1000 + CONDITION["hostname"]["modifier"]
else:
score = 0
break
elif label in CONDITION["user"]["labels"]:
if value == "testuser":
if value.lower() == "testuser":
score += 1000 + CONDITION["user"]["modifier"]
else:
score = 0
@@ -105,12 +105,12 @@ def calculate_score(filename):
def test_score_values(runner, yadm, default, arch, system, distro, cla, host, user):
"""Test score results"""
# pylint: disable=too-many-branches
local_class = "testclass"
local_arch = "testarch"
local_system = "testsystem"
local_distro = "testdistro"
local_host = "testhost"
local_user = "testuser"
local_class = "testClass"
local_arch = "testARch"
local_system = "TESTsystem"
local_distro = "testDISTro"
local_host = "testHost"
local_user = "testUser"
filenames = {"filename##": 0}
if default:

View File

@@ -35,13 +35,13 @@ wrong class 1
{{% if yadm.class != "wronglcass" %}}
Included section from !=
{{% endif\t\t %}}
{{% if yadm.class == "{LOCAL_CLASS}" %}}
{{% if yadm.class == "{LOCAL_CLASS.lower()}" %}}
Included section for class = {{{{yadm.class}}}} ({{{{yadm.class}}}} repeated)
Multiple lines
{{% else %}}
Should not be included...
{{% endif %}}
{{% if yadm.class == "{LOCAL_CLASS2}" %}}
{{% if yadm.class == "{LOCAL_CLASS2.upper()}" %}}
Included section for second class
{{% endif %}}
{{% if yadm.class == "wrongclass2" %}}
@@ -50,7 +50,7 @@ wrong class 2
{{% if yadm.arch == "wrongarch1" %}}
wrong arch 1
{{% endif %}}
{{% if yadm.arch == "{LOCAL_ARCH}" %}}
{{% if yadm.arch == "{LOCAL_ARCH.title()}" %}}
Included section for arch = {{{{yadm.arch}}}} ({{{{yadm.arch}}}} repeated)
{{% endif %}}
{{% if yadm.arch == "wrongarch2" %}}
@@ -59,7 +59,7 @@ wrong arch 2
{{% if yadm.os == "wrongos1" %}}
wrong os 1
{{% endif %}}
{{% if yadm.os == "{LOCAL_SYSTEM}" %}}
{{% if yadm.os == "{LOCAL_SYSTEM.lower()}" %}}
Included section for os = {{{{yadm.os}}}} ({{{{yadm.os}}}} repeated)
{{% endif %}}
{{% if yadm.os == "wrongos2" %}}
@@ -68,7 +68,7 @@ wrong os 2
{{% if yadm.hostname == "wronghost1" %}}
wrong host 1
{{% endif %}}
{{% if yadm.hostname == "{LOCAL_HOST}" %}}
{{% if yadm.hostname == "{LOCAL_HOST.upper()}" %}}
Included section for host = {{{{yadm.hostname}}}} ({{{{yadm.hostname}}}} again)
{{% endif %}}
{{% if yadm.hostname == "wronghost2" %}}
@@ -77,7 +77,7 @@ wrong host 2
{{% if yadm.user == "wronguser1" %}}
wrong user 1
{{% endif %}}
{{% if yadm.user == "{LOCAL_USER}" %}}
{{% if yadm.user == "{LOCAL_USER.title()}" %}}
Included section for user = {{{{yadm.user}}}} ({{{{yadm.user}}}} repeated)
{{% endif %}}
{{% if yadm.user == "wronguser2" %}}
@@ -86,7 +86,7 @@ wrong user 2
{{% if yadm.distro == "wrongdistro1" %}}
wrong distro 1
{{% endif %}}
{{% if yadm.distro == "{LOCAL_DISTRO.upper()}" %}}
{{% if yadm.distro == "{LOCAL_DISTRO.lower()}" %}}
Included section for distro = {{{{yadm.distro}}}} ({{{{yadm.distro}}}} again)
{{% endif %}}
{{% if yadm.distro == "wrongdistro2" %}}
@@ -102,7 +102,7 @@ Included section for distro_family = \
{{% if yadm.distro_family == "wrongfamily2" %}}
wrong family 2
{{% endif %}}
{{% if env.VAR == "{ENV_VAR}" %}}
{{% if env.VAR == "{ENV_VAR.title()}" %}}
Included section for env.VAR = {{{{env.VAR}}}} ({{{{env.VAR}}}} again)
{{% endif %}}
{{% if env.VAR == "wrongenvvar" %}}