INNER CODE UNIT · Python

load_overrides

lissy93/portainer-templates · lib/combine.py:63

def load_overrides():
  """Per-template fixes from overrides.json, keyed by (normalized title, type)."""
  path = os.path.join(BASE_DIR, 'overrides.json')
  if not os.path.isfile(path):
    return {}
  with open(path) as f:
    try:
      entries = json.load(f).get('overrides', [])
    except json.decoder.JSONDecodeError as err:
      log.error(f'Refusing to build: overrides.json is not valid JSON ({err})')
      sys.exit(1)
  return {(normalize_string(e['title']), e.get('type', 1)): e for e in entries
          if isinstance(e, dict) and isinstance(e.get('title'), str) and e['title'].strip()}

def pinned_source(overrides, key):
  """The source file name an override pins this (title, type) to, if any."""
  prefer = overrides.get(key, {}).get('prefer')
  return f'{prefer}.json' if prefer else None

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…