Skip to content

Instantly share code, notes, and snippets.

@achilleas-k
Created June 30, 2022 20:22
Show Gist options
  • Save achilleas-k/7f8982abb7b9477e88d93e0809b4b5f7 to your computer and use it in GitHub Desktop.
Save achilleas-k/7f8982abb7b9477e88d93e0809b4b5f7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
import sys
from typing import Dict, Any
import osbuild.meta
import osbuild.formats
import osbuild.formats.v2
def load(path: str) -> Dict[str, Any]:
with open(path, "r", encoding="utf-8") as path_fp:
return json.load(path_fp)["manifest"]
def main():
manifest_path = sys.argv[1]
manifest_raw = load(manifest_path)
if (ver := manifest_raw.get("version", 1)) != 1:
print(f"{manifest_path} manifest version {ver}: no conversion necessary")
sys.exit(0)
# print(f"Converting {manifest_path} to version 2")
index = osbuild.meta.Index("/usr/lib/osbuild")
info = index.detect_format_info(manifest_raw)
fmt = info.module
manifest = fmt.load(manifest_raw, index)
fmt_v2 = osbuild.formats.v2
res = fmt_v2.describe(manifest, with_id=True)
json.dump(res, sys.stdout)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment