in tools/generator.py [0:0]
def generate(self):
path = self._get_rule_path()
rule = None
if os.path.exists(path):
with open(path, "r") as f:
rule = yaml.safe_load(f)
generated_rule = self._generate_rule()
# reserve some rule sections
if rule:
for section in ("Properties", "Attributes"):
pas = rule.get(section, {}) # props or attrs
generated_pas = generated_rule.setdefault(section, {})
for pa_name, pa in pas.items():
try:
if not pa.get("Ignore") and generated_pas.get(pa_name, {}).get(
"Ignore"
):
generated_pas[pa_name] = pa
except AttributeError as e:
print("-------")
print(generated_pas)
print(pa_name, generated_pas.get(pa_name, {}))
print(e)
raise e
attr_id = rule.get("Attributes", {}).get("id", {}).get("To")
if attr_id:
generated_rule.setdefault("Attributes", {}).setdefault("id", {})[
"To"
] = attr_id
with open(path, "w") as f:
content = yaml.safe_dump(generated_rule, sort_keys=False)
content = content.replace("'# todo'", "# todo")
f.write(content)