Skip to content

Commit

Permalink
Refactoring: improve check_keywords
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Büchse <matthias.buechse@cloudandheat.com>
  • Loading branch information
mbuechse committed Nov 16, 2023
1 parent b854e04 commit 4be3f81
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Tests/scs-compliance-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
import yaml


KEYWORDS_SPEC = ('name', 'url', 'versions', 'prerequisite')
KEYWORDS_VERSION = ('version', 'standards', 'stabilized_at', 'obsoleted_at')
KEYWORDS_STANDARD = ('check_tools', 'url', 'name', 'condition')
KEYWORDS_CHECKTOOL = ('executable', 'args', 'condition', 'classification')
# valid keywords for various parts of the spec, to be checked using `check_keywords`
KEYWORDS = {
'spec': ('name', 'url', 'versions', 'prerequisite'),
'version': ('version', 'standards', 'stabilized_at', 'obsoleted_at'),
'standard': ('check_tools', 'url', 'name', 'condition'),
'checktool': ('executable', 'args', 'condition', 'classification'),
}


def usage(file=sys.stdout):
Expand Down Expand Up @@ -150,7 +153,8 @@ def condition_optional(cond, default=False):
return value


def check_keywords(d, ctx, valid=()):
def check_keywords(ctx, d):
valid = KEYWORDS[ctx]
invalid = [k for k in d if k not in valid]
if invalid:
print(f"ERROR in spec: {ctx} uses unknown keywords: {','.join(invalid)}", file=sys.stderr)
Expand Down Expand Up @@ -191,7 +195,7 @@ def main(argv):
"invokations": {},
},
}
check_keywords(spec, 'spec', KEYWORDS_SPEC)
check_keywords('spec', spec)
if config.version:
spec["versions"] = [vd for vd in spec["versions"] if vd["version"] == config.version]
if "prerequisite" in spec:
Expand All @@ -200,7 +204,7 @@ def main(argv):
memo = report["run"]["invokations"] # memoize check tool results
matches = 0
for vd in spec["versions"]:
check_keywords(vd, 'version', KEYWORDS_VERSION)
check_keywords('version', vd)
stb_date = vd.get("stabilized_at")
obs_date = vd.get("obsoleted_at")
futuristic = not stb_date or config.checkdate < stb_date
Expand All @@ -227,15 +231,15 @@ def main(argv):
aborts = 0
invokations = vr["invokations"]
for standard in vd.get("standards", ()):
check_keywords(standard, 'standard', KEYWORDS_STANDARD)
check_keywords('standard', standard)
optional = condition_optional(standard)
printnq("*******************************************************")
printnq(f"Testing {'optional ' * optional}standard {standard['name']} ...")
printnq(f"Reference: {standard['url']} ...")
if "check_tools" not in standard:
printnq(f"WARNING: No check tool specified for {standard['name']}", file=sys.stderr)
for check in standard.get("check_tools", ()):
check_keywords(check, 'checktool', KEYWORDS_CHECKTOOL)
check_keywords('checktool', check)
if check.get("classification", "light") not in config.classes:
print(f"skipping check tool '{check['executable']}' because of resource classification")
continue
Expand Down

0 comments on commit 4be3f81

Please sign in to comment.