INNER CODE UNIT · Python

load_sources

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

def load_sources(sources):
  """Load and merge all template JSON files from sources/local/ and sources/external/."""
  rank = source_priority(sources)
  templates = []
  local_dir = os.path.join(SOURCES_DIR, 'local')
  external_dir = os.path.join(SOURCES_DIR, 'external')
  for is_local, d in [(True, local_dir), (False, external_dir)]:
    if not os.path.isdir(d):
      continue
    for file in sorted(os.listdir(d)):
      file_path = os.path.join(d, file)
      if not (os.path.isfile(file_path) and file.endswith('.json')):
        continue
      with open(file_path) as f:
        try:
          source_templates = json.load(f)['templates']
        except (json.decoder.JSONDecodeError, KeyError) as err:
          log.warning(f'Skipping source due to error: {f.name} ({err})')

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…