INNER CODE UNIT · Python
normalize_category
lissy93/portainer-templates · lib/combine.py:34
def normalize_category(c):
"""Split a category into words and title-case it for display"""
if not isinstance(c, str):
return ''
# Some sources namespace their categories, and the subtype is the useful half
c = c.rsplit(':', 1)[-1].strip() or c
words = [w for w in re.split(r'[^0-9a-zA-Z]+', c) if w]
label = ' '.join(w.upper() if w.lower() in CATEGORY_ACRONYMS else w.capitalize()
for w in words)
return 'edge' if label == 'Edge' else label
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