INNER CODE UNIT · Python
template_score
lissy93/portainer-templates · lib/combine.py:45
def template_score(t):
"""Score a template's completeness. Higher is more complete."""
score = len(t) # number of top-level keys
score += len(t.get('env', []))
score += len(t.get('volumes', []))
score += len(t.get('ports', []))
return score
def template_rank(t, pinned=None):
"""Sort key for choosing between duplicates, higher wins: pinned source, then source
priority, then completeness."""
return (t['_source'] == pinned, -t['_priority'], template_score(t))
def source_priority(sources):
"""File name -> dedup priority, lower wins: app sources first, then sources.csv order"""
ordered = [s for s in sources if s.is_app] + [s for s in sources if not s.is_app]
return {s.filename: i for i, s in enumerate(ordered, start=1)}