|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# This script should be run at the top level of the langkit-query-language with |
| 4 | +# PYTHONPATH set to the impact-db repository path. The impact-db repository path |
| 5 | +# should also be passed as first argument: |
| 6 | +# |
| 7 | +# $ PYTHONPATH=/path/to/impact-db ./impact-db_impacts_gen.py /path/to/impact-db |
| 8 | + |
| 9 | +import glob |
| 10 | +import json |
| 11 | +import sys |
| 12 | +from pathlib import Path |
| 13 | +from impactdb import db |
| 14 | + |
| 15 | +impactdb_dir = sys.argv[1] |
| 16 | +res = {} |
| 17 | + |
| 18 | + |
| 19 | +def format_impacts(impacts: [str]) -> str: |
| 20 | + gnat = list(db.config["gnat"].keys()) |
| 21 | + return ",".join(list(map(lambda i: i + ".*" if i in gnat else i, impacts))) |
| 22 | + |
| 23 | + |
| 24 | +def format_name(name: str) -> str: |
| 25 | + return "kp_" + name.lower().replace("-", "_") |
| 26 | + |
| 27 | + |
| 28 | +def list_impacts(issues: [str]) -> None: |
| 29 | + entries = [e for e in db.load(impactdb_dir + "/entries") if e.type == "kp"] |
| 30 | + for e in entries: |
| 31 | + if e.name in issues: |
| 32 | + res.update({format_name(e.name): format_impacts(e.impacts)}) |
| 33 | + elif e.origin in issues: |
| 34 | + res.update({format_name(e.origin): format_impacts(e.impacts)}) |
| 35 | + |
| 36 | + |
| 37 | +kps = [kp for kp in glob.glob("./lkql_checker/share/lkql/kp/KP-*")] |
| 38 | +ids = [Path(id).stem[3:] for id in kps] |
| 39 | +list_impacts(ids) |
| 40 | + |
| 41 | +impacts = {"impacts": res} |
| 42 | +impacts.update({"gnat": list(db.config["gnat"].keys())}) |
| 43 | + |
| 44 | +with open("./lkql_checker/share/lkql/kp/kp.json", "w", encoding="utf-8") as f: |
| 45 | + json.dump(impacts, f, ensure_ascii=False, indent=4) |
| 46 | + |
| 47 | +with open("./lkql_checker/share/lkql/kp/kp.json", "a", encoding="utf-8") as f: |
| 48 | + f.write("\n") |
0 commit comments