From 5555586561cfcc9efd63bfb98eda6d66d58e605e Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Tue, 2 Nov 2021 23:10:24 +0800 Subject: [PATCH] nodes init --- .../config.json" | 4 +- .../config.json" | 4 +- .../config.json" | 4 +- .../config.json" | 4 +- data/config.json | 6 +++ data/tree.json | 37 +++++++++++++++++++ src/tree.py | 4 +- 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 data/config.json create mode 100644 data/tree.json diff --git "a/data/1.toolchains\345\210\235\351\230\266/1.GIT\345\205\245\351\227\250/config.json" "b/data/1.toolchains\345\210\235\351\230\266/1.GIT\345\205\245\351\227\250/config.json" index 89f6188..d6aaccb 100644 --- "a/data/1.toolchains\345\210\235\351\230\266/1.GIT\345\205\245\351\227\250/config.json" +++ "b/data/1.toolchains\345\210\235\351\230\266/1.GIT\345\205\245\351\227\250/config.json" @@ -1,3 +1,5 @@ { - "keywords": [] + "keywords": [], + "node_id": "c-1cf412c0785c4269a2a4cc7634aa101b", + "title": "GIT入门" } \ No newline at end of file diff --git "a/data/1.toolchains\345\210\235\351\230\266/config.json" "b/data/1.toolchains\345\210\235\351\230\266/config.json" index 89f6188..22e3506 100644 --- "a/data/1.toolchains\345\210\235\351\230\266/config.json" +++ "b/data/1.toolchains\345\210\235\351\230\266/config.json" @@ -1,3 +1,5 @@ { - "keywords": [] + "keywords": [], + "node_id": "c-5995c3ccf1554d1ca4e48da52cf6aed9", + "title": "toolchains初阶" } \ No newline at end of file diff --git "a/data/2.toolchains\344\270\255\351\230\266/config.json" "b/data/2.toolchains\344\270\255\351\230\266/config.json" index 89f6188..5c2bc98 100644 --- "a/data/2.toolchains\344\270\255\351\230\266/config.json" +++ "b/data/2.toolchains\344\270\255\351\230\266/config.json" @@ -1,3 +1,5 @@ { - "keywords": [] + "keywords": [], + "node_id": "c-671b93fb441b44bd86020a6c5ecb689b", + "title": "toolchains中阶" } \ No newline at end of file diff --git "a/data/3.toolchains\351\253\230\351\230\266/config.json" "b/data/3.toolchains\351\253\230\351\230\266/config.json" index 89f6188..f17c3d7 100644 --- "a/data/3.toolchains\351\253\230\351\230\266/config.json" +++ "b/data/3.toolchains\351\253\230\351\230\266/config.json" @@ -1,3 +1,5 @@ { - "keywords": [] + "keywords": [], + "node_id": "c-60527be7abb340d39a1d4a4e780b402c", + "title": "toolchains高阶" } \ No newline at end of file diff --git a/data/config.json b/data/config.json new file mode 100644 index 0000000..f201a93 --- /dev/null +++ b/data/config.json @@ -0,0 +1,6 @@ +{ + "tree_name": "Toolchains", + "keywords": [], + "node_id": "c-9ae45d2c41cd4958a449b8f50a394fcc", + "title": "C" +} \ No newline at end of file diff --git a/data/tree.json b/data/tree.json new file mode 100644 index 0000000..9911e4b --- /dev/null +++ b/data/tree.json @@ -0,0 +1,37 @@ +{ + "Toolchains": { + "node_id": "c-9ae45d2c41cd4958a449b8f50a394fcc", + "keywords": [], + "children": [ + { + "toolchains初阶": { + "node_id": "c-5995c3ccf1554d1ca4e48da52cf6aed9", + "keywords": [], + "children": [ + { + "GIT入门": { + "node_id": "c-1cf412c0785c4269a2a4cc7634aa101b", + "keywords": [], + "children": [] + } + } + ] + } + }, + { + "toolchains中阶": { + "node_id": "c-671b93fb441b44bd86020a6c5ecb689b", + "keywords": [], + "children": [] + } + }, + { + "toolchains高阶": { + "node_id": "c-60527be7abb340d39a1d4a4e780b402c", + "keywords": [], + "children": [] + } + } + ] + } +} \ No newline at end of file diff --git a/src/tree.py b/src/tree.py index 0c64f2d..ba3287e 100644 --- a/src/tree.py +++ b/src/tree.py @@ -21,7 +21,7 @@ def dump_json(p, j, exist_ok=False, override=False): print(f"{p} already exist") sys.exit(0) - with open(p, 'w') as f: + with open(p, 'w+') as f: f.write(json.dumps(j, indent=2, ensure_ascii=False)) @@ -117,7 +117,7 @@ def gen_tree(data_path): cfg_path = os.path.join(data_path, 'config.json') cfg = load_json(cfg_path) if ensure_node_id(cfg): - dump_json(cfg_path, cfg) + dump_json(cfg_path, cfg, exist_ok=True, override=True) if ensure_title(cfg, cfg_path): cfg["title"] = "C" -- GitLab