Commit d2ced8b8 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Scripts: Add

parent 390218a8
from typing import Any
from typing import Dict
from typing import Iterator
import sys
import json
import logging
from collections import defaultdict
from pathlib import Path
from zipfile import ZipFile
FORMAT = '%(asctime)s %(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
log = logging.getLogger()
REQUIRED_KEYS: set[str] = {
PACKAGE_INDEX: dict[str, Any] = {
'metadata': {
'repository_name': 'master',
'image_url': '',
'plugins': defaultdict(dict)
def is_manifest_valid(manifest: dict[str, Any]) -> bool:
manifest_keys = set(manifest.keys())
return REQUIRED_KEYS.issubset(manifest_keys)
def iter_releases(release_folder: Path) -> Iterator[Dict[str, Any]]:
for path in release_folder.rglob('*.zip'):
with ZipFile(path) as release_zip:
with'manifest.json') as file:
manifest = json.load(file)
yield manifest
except Exception:
log.error('Error loading manifest')
def build_package_index(release_folder: Path) -> None:'Build package index')
for manifest in iter_releases(release_folder):
if not is_manifest_valid(manifest):
log.warning('Invalid manifest')
short_name = manifest.pop('short_name')
version = manifest.pop('version')
PACKAGE_INDEX['plugins'][short_name][version] = manifest'Found manifest: %s - %s', short_name, version)
path = release_folder / 'package_index.json'
with'w') as f:
json.dump(PACKAGE_INDEX, f)
def build_image_zip(release_folder: Path) -> None:'Build')
with ZipFile(release_folder / '', mode='w') as image_zip:
for path in release_folder.iterdir():
if not path.is_dir():
image = path / f'{}.png'
if not image.exists():
if __name__ == '__main__':
path = Path(sys.argv[1])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment