You've already forked open-source-firmware-validation
mirror of
https://github.com/Dasharo/open-source-firmware-validation.git
synced 2026-03-06 14:51:55 -08:00
cf836be8e0
Signed-off-by: Filip Gołaś <filip.golas@3mdeb.com>
35 lines
729 B
Python
35 lines
729 B
Python
#!/usr/bin/env python3
|
|
|
|
# SPDX-FileCopyrightText: 2025 3mdeb <contact@3mdeb.com>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import json
|
|
import sys
|
|
|
|
if len(sys.argv) < 2:
|
|
print(f"Usage: {sys.argv[0]} input.json", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
with open(sys.argv[1], "r", encoding="utf-8") as f:
|
|
data = json.load(f)
|
|
|
|
|
|
def doc(e):
|
|
return e.get("doc", e)
|
|
|
|
|
|
best, order = {}, []
|
|
for e in data:
|
|
_id = doc(e).get("_id")
|
|
if not _id:
|
|
continue
|
|
if _id not in best:
|
|
best[_id] = e
|
|
order.append(_id)
|
|
else:
|
|
if ("changed_to" in doc(e)) and ("changed_to" not in doc(best[_id])):
|
|
best[_id] = e
|
|
|
|
json.dump([best[i] for i in order], sys.stdout, indent=2, ensure_ascii=False)
|