From 577d8251a22f430f8d634e5a2568e983e5c5c171 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Wed, 24 Nov 2021 03:09:25 +0800 Subject: [PATCH] fixed odd orders --- src/tree.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tree.py b/src/tree.py index bb8e879..8317aba 100644 --- a/src/tree.py +++ b/src/tree.py @@ -243,19 +243,25 @@ class TreeWalker: config = load_json(config_path) flag, result = self.ensure_node_id(config) if flag: - dump_json(config_path, config, exist_ok=True, override=True) + dump_json(config_path, result, exist_ok=True, override=True) return config def ensure_node_id(self, config): + flag = False if "node_id" not in config or \ not config["node_id"].startswith(f"{self.tree}-") or \ config["node_id"] in id_set: new_id = self.gen_node_id() id_set.add(new_id) config["node_id"] = new_id - return True, config - else: - return False, config + flag = True + + for child in config.get("children", []): + child_node = list(child.values())[0] + f, _ = self.ensure_node_id(child_node) + flag = flag or f + + return flag, config def gen_node_id(self): return f"{self.name}-{uuid.uuid4().hex}" -- GitLab