INNER CODE UNIT · Python

templates_at

lissy93/portainer-templates · lib/changelog.py:54

def templates_at(tag):
    """Templates in templates.json at a tag, keyed by title with `id` dropped.
    Returns None if the file doesn't exist at that tag."""
    try:
        raw = git('show', f'{tag}:templates.json')
    except subprocess.CalledProcessError:
        return None
    templates = json.loads(raw).get('templates', [])
    return {t['title']: {k: v for k, v in t.items() if k != 'id'}
            for t in templates if isinstance(t, dict) and 'title' in t}

def by_name(template):
    """Bare letters and digits of a title, so 'Node Red' and 'Node-Red' match"""
    return re.sub(r'[^a-z0-9]', '', template['title'].lower())

def by_body(template):
    """Every field but the title, so a template under a new name still matches"""
    return json.dumps({k: v for k, v in template.items() if k != 'title'}, sort_keys=True)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…