From 7800d2086131ae698f859f0797a5670cace48213 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Dec 2020 20:11:26 +0100 Subject: Dumping to yaml files. --- main.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'main.py') diff --git a/main.py b/main.py index 60164f2..445ab5a 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,8 @@ from durable.engine import MessageObservedException from durable.lang import * +import os +import os.path +import yaml class VimScore: @staticmethod @@ -169,3 +172,48 @@ print("PHASE 2") for f in [f for f in get_facts("my-rules") if f["type"] in ("dba-cluster", "dba-container")]: assert_fact("phase-2", f) + +def write_facts(ruleset: set): + facts = get_facts(ruleset) + + types = set((f.get("type") for f in facts)) + + print(f"types: {types}") + + out_dir = "out" + if not os.path.exists(out_dir): + os.mkdir(out_dir) + + basedir = os.path.join(out_dir, ruleset) + if os.path.exists(basedir): + for f in os.listdir(basedir): + p = os.path.join(basedir, f) + if os.path.isdir(p): + for f2 in os.listdir(p): + os.remove(os.path.join(p, f2)) + os.rmdir(p) + else: + os.remove(p) + os.rmdir(basedir) + os.mkdir(basedir) + + for t in types: + typedir = os.path.join(basedir, t) + os.mkdir(typedir) + + fs = [] + for f in facts: + if f["type"] != t: + continue + del f["sid"] + fs.append(f) + + i = 0 + for fact in fs: + path = os.path.join(typedir, str(i) + ".yaml") + with open(path, "w") as f: + s = yaml.dump(fact) + f.write(s) + i = i + 1 + +write_facts("phase-2") -- cgit v1.2.3