“8c81d9949eea828acb76079c685402f6c26c2059”上不存在“git@gitcode.net:Crayonxin2000/Paddle.git”
提交 83428604 编写于 作者: M Mars Liu

fxied bug in tree.py

上级 2318de26
{
"type": "code_options",
"author": "幻灰龙",
"source": "standard.md"
"source": "standard.md",
"exercise_id": "8150ef23aad248f78110f33e34754311"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "compiler.md"
"source": "compiler.md",
"exercise_id": "b812499b338541d2955575e56c116da9"
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"vla.json"
]
"export": []
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"pointers_2_func.json"
]
"export": []
}
\ No newline at end of file
......@@ -7,7 +7,5 @@
"C语言"
],
"children": [],
"export": [
"linked_list.json"
]
"export": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "bin_to_hex.md"
"source": "bin_to_hex.md",
"exercise_id": "bfae271b73284a6fa5f48bcde4a7f3e0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "bit_op.md"
"source": "bit_op.md",
"exercise_id": "0952044cc5e54770b7418ed868d201a2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "pack01.md"
"source": "pack01.md",
"exercise_id": "4aa8ae84487d433e943a5a9ef6293dbd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "pack02.md"
"source": "pack02.md",
"exercise_id": "03f964d865b54fe9947e728585a27486"
}
\ No newline at end of file
......@@ -6,7 +6,5 @@
"C语言"
],
"children": [],
"export": [
"enum.json"
]
"export": []
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"inline01.json"
]
"export": []
}
\ No newline at end of file
......@@ -6,7 +6,5 @@
"C语言"
],
"children": [],
"export": [
"file_hash.json"
]
"export": []
}
\ No newline at end of file
......@@ -5,20 +5,24 @@
"children": [
{
"C语言初阶": {
"node_id": "8699564e59bd4972a2aae85e7e198c4d",
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [
{
"C语言概述": {
"node_id": "ff93d18873424490849cdcf2ca01a48b",
"keywords": [],
"keywords": [
"概述",
"C语言概述",
"C语言"
],
"children": [
{
"C语言发展史": {
"node_id": "8c3cdf9ae7b547adbd99c360246bf2b2",
"keywords": [
"C语言概述",
"概述",
"C语言发展史",
"发展史",
"C语言"
],
"children": [
......@@ -226,7 +230,7 @@
"C语言"
],
"children": [],
"node_id": "d8484b58a8724720bc603c7f4502c663"
"node_id": "557cbf68f22a4747b8992615ad643fa8"
}
},
{
......@@ -237,7 +241,7 @@
"C语言"
],
"children": [],
"node_id": "5df2b51772a347d0af0e58a58fe2dddb"
"node_id": "33b51bd99ba743c090b8050e3e784470"
}
},
{
......@@ -247,7 +251,7 @@
"C语言"
],
"children": [],
"node_id": "820683ecd76749c4bdd1cf67c1a638d2"
"node_id": "d78d438e88454d1fa7dd12676b100e0c"
}
},
{
......@@ -258,7 +262,7 @@
"C语言"
],
"children": [],
"node_id": "c3dba269f7234c259fd5a86cb32fe14e"
"node_id": "be25cc23301b4373940b6eff8291bb05"
}
},
{
......@@ -268,7 +272,7 @@
"C语言"
],
"children": [],
"node_id": "a2e960e51c174ada94e889beb01b89c1"
"node_id": "a9c21fb270414f5d8599b1eea5e6a59f"
}
},
{
......@@ -281,7 +285,7 @@
"C语言"
],
"children": [],
"node_id": "bb2a19fec37745c4bad917d57da0a9cd"
"node_id": "4b692f5904ff4c70a44a648f47c024d4"
}
},
{
......@@ -292,7 +296,7 @@
"C语言"
],
"children": [],
"node_id": "9bd2fc9f48be469bb057b46f99f0b9e3"
"node_id": "68819aeb078d4ce4a6538b8a548c0eea"
}
},
{
......@@ -303,7 +307,7 @@
"C语言"
],
"children": [],
"node_id": "ac1afe2e796b45e4b191db769245c33a"
"node_id": "908f40d645f4410680fbab6feddab8b2"
}
}
]
......@@ -316,7 +320,7 @@
"数据类型": {
"node_id": "c7ef387bd4bf4bd0a87d1886e66160c5",
"keywords": [
"编程机制",
"数据类型",
"C语言"
],
"children": [
......@@ -355,7 +359,7 @@
"int"
],
"children": [],
"node_id": "714e6165568248aeb284356eeb0821c0"
"node_id": "4b8c956c12dd4d59a3ebdab97bac590d"
}
},
{
......@@ -366,7 +370,7 @@
"double"
],
"children": [],
"node_id": "bc91e7bffb97458bb9d5143c52b8b84c"
"node_id": "50a4fd5c83bf4f558d7cc9cc27c39c90"
}
},
{
......@@ -376,7 +380,7 @@
"char"
],
"children": [],
"node_id": "3caf78e68a2a4cb38db14f8d2aeb8864"
"node_id": "8cff086ba20b4cc88f07dbb3dc8e7c38"
}
},
{
......@@ -386,7 +390,7 @@
"boll"
],
"children": [],
"node_id": "6d00d6533afd4f8eb0b7974315888381"
"node_id": "1702c0269b714bf3a5b00e366a71a829"
}
}
]
......@@ -399,8 +403,9 @@
"运算符与表达式": {
"node_id": "5002624ecc8d4be1a3d8eab4579ac7b8",
"keywords": [
"基本数据类型",
"数据类型"
"运算符",
"表达式",
"运算符与表达式"
],
"children": [
{
......@@ -409,7 +414,9 @@
"keywords": [
"赋值",
"运算符",
"表达式",
"赋值运算符",
"赋值表达式",
"C语言"
],
"children": []
......@@ -421,7 +428,9 @@
"keywords": [
"算术",
"算术运算符",
"算术表达式",
"运算符",
"表达式",
"C语言"
],
"children": [
......@@ -504,7 +513,9 @@
"keywords": [
"关系",
"关系运算符",
"关系表达式",
"运算符",
"表达式",
"C语言"
],
"children": [
......@@ -577,6 +588,8 @@
"keywords": [
"逻辑",
"逻辑运算符",
"逻辑表达式",
"表达式",
"运算符",
"C语言"
],
......@@ -621,7 +634,11 @@
"逗号运算符与表达式": {
"node_id": "d8047c9c975b457cbc30445ff78787d6",
"keywords": [
"逗号",
"运算符",
"表达式",
"逗号运算符",
"逗号表达式",
"C语言"
],
"children": []
......@@ -633,6 +650,8 @@
"keywords": [
"条件",
"条件运算符",
"条件表达式",
"表达式",
"运算符",
"C语言"
],
......@@ -643,6 +662,8 @@
"sizeof运算符": {
"node_id": "a78c62afc42f45178a799ff67c9fd330",
"keywords": [
"sizeof运算符",
"sizeof",
"运算符",
"C语言"
],
......@@ -654,6 +675,10 @@
"node_id": "eb5b902755f24674bce31bde2ce4f439",
"keywords": [
"运算符",
"优先级",
"求值顺序",
"运算符优先级",
"运算符求值顺序",
"C语言"
],
"children": []
......@@ -666,7 +691,9 @@
"语句与控制流": {
"node_id": "18bef4edbf9a498fa3838246cd733986",
"keywords": [
"运算符",
"语句与控制流",
"语句",
"控制流",
"C语言"
],
"children": [
......@@ -675,7 +702,8 @@
"node_id": "a88a08b3d3a24780b94e2809336202b5",
"keywords": [
"语句",
"控制流",
"程序块",
"语句与程序块",
"C语言"
],
"children": []
......@@ -685,8 +713,9 @@
"判断语句": {
"node_id": "0c86f68dfe7c4a4ca6c8b7c12135fd43",
"keywords": [
"判断语句",
"判断",
"语句",
"控制流",
"C语言"
],
"children": [
......@@ -746,7 +775,8 @@
"node_id": "bc001e483b8c41a8a7ccc369393d636a",
"keywords": [
"语句",
"控制流",
"循环",
"循环语句",
"C语言"
],
"children": [
......@@ -826,20 +856,27 @@
},
{
"C语言中阶": {
"node_id": "a311b31b4bda403f99963cffd92e6306",
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [
{
"函数与程序结构": {
"node_id": "c1d5e45aeba9407a9aba96de5af95e4e",
"keywords": [],
"keywords": [
"函数",
"程序结构",
"C语言"
],
"children": [
{
"函数的声明与定义": {
"node_id": "e2785c48975d4b32917e89a5c260ae27",
"keywords": [
"函数",
"程序结构",
"声明",
"定义",
"函数声明",
"函数定义",
"C语言"
],
"children": []
......@@ -850,7 +887,8 @@
"node_id": "30a5dee1088c403b81ae2d61f717f214",
"keywords": [
"函数",
"程序结构",
"参数",
"函数参数",
"C语言"
],
"children": []
......@@ -861,7 +899,9 @@
"node_id": "bfff88a1a24e4eb98577ac663c44da09",
"keywords": [
"函数",
"程序结构",
"返回",
"返回值",
"函数返回",
"C语言"
],
"children": []
......@@ -872,7 +912,8 @@
"node_id": "67a79ded33aa459e81f953aea62b5b65",
"keywords": [
"函数",
"程序结构",
"调用",
"函数调用",
"C语言"
],
"children": []
......@@ -883,7 +924,8 @@
"node_id": "978a26e7ad464c5481ce0c56480ed60d",
"keywords": [
"函数",
"程序结构",
"递归",
"函数递归",
"C语言"
],
"children": []
......@@ -893,8 +935,8 @@
"局部变量和全局变量": {
"node_id": "293ce0005b924bd7b76216d395e021f2",
"keywords": [
"C语言概述",
"概述",
"局部变量",
"全局变量",
"C语言"
],
"children": []
......@@ -904,8 +946,7 @@
"头文件": {
"node_id": "9b668f9078814a86b5d45265f2d87186",
"keywords": [
"函数",
"程序结构",
"头文件",
"C语言"
],
"children": []
......@@ -915,8 +956,8 @@
"内部函数和外部函数": {
"node_id": "c4862064e784410fb4ee6f54e2c74e7a",
"keywords": [
"函数",
"程序结构",
"内部函数",
"外部函数",
"C语言"
],
"children": []
......@@ -929,8 +970,7 @@
"数组": {
"node_id": "aab5230436134bc0ae4334f20616646b",
"keywords": [
"函数",
"程序结构",
"数组",
"C语言"
],
"children": [
......@@ -938,6 +978,7 @@
"数组简介": {
"node_id": "4103c3071b694c778cdee1f78150b3dd",
"keywords": [
"数组简介",
"数组",
"C语言"
],
......@@ -948,6 +989,7 @@
"一维数组": {
"node_id": "50bb5756ca6f4fab9db632226f95ef13",
"keywords": [
"一维数组",
"数组",
"C语言"
],
......@@ -959,6 +1001,7 @@
"node_id": "f9e454c8bac54e17a358aa3537f80f2b",
"keywords": [
"数组",
"二维数组",
"C语言"
],
"children": []
......@@ -969,6 +1012,7 @@
"node_id": "ba9bbb9164584d7285e469c5aa34b8aa",
"keywords": [
"数组",
"变长数组",
"C语言"
],
"children": []
......@@ -981,7 +1025,7 @@
"指针": {
"node_id": "9e7cea0fd7294892be114dbb7fbc9b30",
"keywords": [
"数组",
"指针",
"C语言"
],
"children": [
......@@ -989,6 +1033,7 @@
"指针与地址": {
"node_id": "b56d0beb05d8468a92b5127af497f66b",
"keywords": [
"地址",
"指针",
"C语言"
],
......@@ -999,6 +1044,7 @@
"指针与函数参数": {
"node_id": "c125ac53cc324775abe8604efe6ba023",
"keywords": [
"函数参数",
"指针",
"C语言"
],
......@@ -1009,6 +1055,7 @@
"指针与数组": {
"node_id": "826682a938a0422390dcf4d3f7b933b4",
"keywords": [
"数组",
"指针",
"C语言"
],
......@@ -1019,6 +1066,8 @@
"地址算术运算": {
"node_id": "2301f0c532c143c28e3261b442743f05",
"keywords": [
"地址算术运算",
"算术运算",
"指针",
"C语言"
],
......@@ -1029,6 +1078,8 @@
"指针数组以及指向指针的指针": {
"node_id": "86987ec92a6b441abc05a9dc616e3075",
"keywords": [
"指针数组",
"指针的指针",
"指针",
"C语言"
],
......@@ -1040,6 +1091,8 @@
"node_id": "fa927c0947f3427aafee3415e11694e7",
"keywords": [
"指针",
"函数指针",
"指向函数的指针",
"C语言"
],
"children": []
......@@ -1052,7 +1105,7 @@
"字符串": {
"node_id": "60997c5d19b84545abb2adbac24351bc",
"keywords": [
"指针",
"字符串",
"C语言"
],
"children": [
......@@ -1060,8 +1113,11 @@
"字符串输入与输出": {
"node_id": "bbd1310e647846018a1ff37d29c70ff0",
"keywords": [
"C语言概述",
"概述",
"字符串输出",
"字符串输入",
"输出",
"输入",
"字符串",
"C语言"
],
"children": []
......@@ -1071,8 +1127,8 @@
"字符串函数": {
"node_id": "2aa6707a4e0244dfab606b030f5c35c9",
"keywords": [
"C语言概述",
"概述",
"字符串函数",
"字符串",
"C语言"
],
"children": []
......@@ -1086,18 +1142,22 @@
},
{
"C语言高阶": {
"node_id": "307890a9cb4543b08f52b4b0a7fe9933",
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"children": [
{
"结构体": {
"node_id": "457fbccd00ef4ce3b0f44702f9755b43",
"keywords": [],
"keywords": [
"结构体",
"C语言"
],
"children": [
{
"结构体简介": {
"node_id": "86b95a1e3e084e7c92fa959b731d81dc",
"keywords": [
"结构体简介",
"结构体",
"C语言"
],
......@@ -1108,6 +1168,7 @@
"结构体数组": {
"node_id": "e970a52419484d11bcdd097d713b065e",
"keywords": [
"结构体数组",
"结构体",
"C语言"
],
......@@ -1118,6 +1179,7 @@
"结构体指针": {
"node_id": "c41c3c9229594a619abb2295be13a789",
"keywords": [
"结构体指针",
"结构体",
"C语言"
],
......@@ -1128,6 +1190,8 @@
"结构体与函数": {
"node_id": "11a69657ca7d422d9a08ecef807f1600",
"keywords": [
"结构体与函数",
"函数",
"结构体",
"C语言"
],
......@@ -1138,6 +1202,8 @@
"链式结构": {
"node_id": "a6978054585b44acb482eea3d9e4aefc",
"keywords": [
"链式结构",
"链表",
"结构体",
"C语言"
],
......@@ -1151,7 +1217,9 @@
"联合体与枚举类型": {
"node_id": "6a54244141664f8a9fe626d564bb150f",
"keywords": [
"结构体",
"枚举类型",
"联合体",
"共用体",
"C语言"
],
"children": [
......@@ -1160,7 +1228,8 @@
"node_id": "65fbcb8587ab432895bbfb7d873d17de",
"keywords": [
"联合体",
"共用体"
"共用体",
"C语言"
],
"children": []
}
......@@ -1170,7 +1239,8 @@
"node_id": "a18e6c6aef644580a7e9743087cb8fd8",
"keywords": [
"枚举",
"枚举类型"
"枚举类型",
"C语言"
],
"children": []
}
......@@ -1182,27 +1252,28 @@
"位运算": {
"node_id": "f0296e72f7c441f0b0eee5a854580022",
"keywords": [
"枚举",
"枚举类型"
"位运算",
"位操作",
"C语言"
],
"children": [
{
"位和字节": {
"node_id": "cfe3277172e24a0587fc7b9dca6b8633",
"keywords": [
"位运算",
"位操作",
"位和字节",
"字节",
"C语言"
],
"children": []
}
},
{
"二进制": {
"二进制": {
"node_id": "18a259dd149a4ad4b51ca76cece73575",
"keywords": [
"位运算",
"位操作",
"二进制",
"2进制",
"C语言"
],
"children": []
......@@ -1212,8 +1283,8 @@
"八进制": {
"node_id": "d09ce6bde4bd4d43b5bda77b98328367",
"keywords": [
"位运算",
"位操作",
"八进制",
"8进制",
"C语言"
],
"children": []
......@@ -1223,8 +1294,8 @@
"十六进制": {
"node_id": "2caff3956d7e43c08c46cdcf8f8b6f29",
"keywords": [
"位运算",
"位操作",
"十六进制",
"16进制",
"C语言"
],
"children": []
......@@ -1235,29 +1306,28 @@
"node_id": "d199fcbcb452465696fadddafbfb26e1",
"keywords": [
"位运算",
"位操作",
"位逻辑运算",
"C语言"
],
"children": []
}
},
{
"位字段": {
"node_id": "044247ccf6324f749dd6fcecb6fd7c1f",
"对齐特性": {
"node_id": "501dc3e5d4da44fe8ba5614875d9cbdf",
"keywords": [
"对齐特性",
"位运算",
"位操作",
"C语言"
],
"children": []
}
},
{
"对齐特性": {
"node_id": "501dc3e5d4da44fe8ba5614875d9cbdf",
"位字段": {
"node_id": "044247ccf6324f749dd6fcecb6fd7c1f",
"keywords": [
"位运算",
"位操作",
"位字段",
"C语言"
],
"children": []
......@@ -1270,8 +1340,8 @@
"预处理器": {
"node_id": "4c711f0dc45c49e39f2dbdb5f89008a9",
"keywords": [
"位运算",
"位操作",
"预处理器",
"预编译器",
"C语言"
],
"children": [
......@@ -1279,8 +1349,7 @@
"宏定义": {
"node_id": "81ca2e0059a547db93cb10c8352a3687",
"keywords": [
"预处理器",
"预编译器",
"宏定义",
"C语言"
],
"children": []
......@@ -1290,8 +1359,8 @@
"#include指令": {
"node_id": "a9536f1fcd9242fc96a358be560ff7b1",
"keywords": [
"预处理器",
"预编译器",
"include",
"#include",
"C语言"
],
"children": []
......@@ -1301,8 +1370,8 @@
"#undef指令": {
"node_id": "9177a200808c4d879116a4a69e89df41",
"keywords": [
"预处理器",
"预编译器",
"undef",
"#undef",
"C语言"
],
"children": []
......@@ -1312,7 +1381,7 @@
"条件编译": {
"node_id": "d962e7c6c96d431ea38e6e6aed7728b6",
"keywords": [
"预处理器",
"条件编译",
"预编译器",
"C语言"
],
......@@ -1323,8 +1392,7 @@
"内联函数": {
"node_id": "d21d6de040954559abee2dbad03ac4d1",
"keywords": [
"预处理器",
"预编译器",
"内联函数",
"C语言"
],
"children": []
......@@ -1337,8 +1405,7 @@
"文件": {
"node_id": "4877d759ed524ba086a8dd6bc00c2e86",
"keywords": [
"预处理器",
"预编译器",
"文件",
"C语言"
],
"children": [
......@@ -1347,6 +1414,7 @@
"node_id": "6ac7da2c6a894cc2ad4a2facb2aec07a",
"keywords": [
"文件",
"文件基本操作",
"C语言"
],
"children": [
......@@ -1390,6 +1458,7 @@
"node_id": "c9f455f9665042b5bdfd19918e34cc94",
"keywords": [
"文件",
"文件读写",
"C语言"
],
"children": []
......@@ -1402,7 +1471,8 @@
"存储管理": {
"node_id": "d127f044a075402788e20b3cb690a328",
"keywords": [
"文件",
"存储管理",
"内存管理",
"C语言"
],
"children": [
......@@ -1410,19 +1480,38 @@
"存储类别": {
"node_id": "055d9ba0f2864f78a5fea826aded5aaa",
"keywords": [
"存储管理",
"内存管理",
"存储类别",
"C语言"
],
"children": []
}
},
{
"分配内存:malloc()和free()": {
"内存动态管理": {
"node_id": "e75bdc3470954cb38bdfcf4f0ed3680b",
"keywords": [
"存储管理",
"内存管理",
"内存动态管理",
"C语言"
],
"children": [
{
"内存分配:malloc()": {
"keywords": [
"内存分配",
"malloc",
"C语言"
],
"children": [],
"node_id": "db508a67e5fa4092ae5f130e59e15941"
}
},
{
"内存释放:free()": {
"keywords": [
"内存释放",
"free",
"C语言"
],
"children": []
......@@ -1430,13 +1519,16 @@
}
]
}
}
]
}
},
{
"标准函数库": {
"node_id": "a95ae0dfca614dab8b02ef4b96d7398d",
"keywords": [
"存储管理",
"内存管理",
"标准函数库",
"标准库",
"C语言"
],
"children": [
......@@ -1444,7 +1536,8 @@
"数学库": {
"node_id": "77363abd916c4981b595f44138f53e0a",
"keywords": [
"标准函数库",
"数学库",
"math.h",
"标准库",
"C语言"
],
......@@ -1455,7 +1548,8 @@
"通用工具库": {
"node_id": "dab1add961df46479031b66bc52a00b0",
"keywords": [
"标准函数库",
"stdlib.h",
"通用工具库",
"标准库",
"C语言"
],
......@@ -1463,10 +1557,11 @@
}
},
{
"断言库 ": {
"断言库": {
"node_id": "2ce0d5349c454d099692a07c2a32a56d",
"keywords": [
"标准函数库",
"assert.h",
"断言库",
"标准库",
"C语言"
],
......
......@@ -37,6 +37,19 @@ def parse_no_name(d):
return no, dir_name
def check_export(base, cfg):
flag = False
exports = []
for export in cfg.get('export', []):
ecfg_path = os.path.join(base, export)
if os.path.exists(ecfg_path):
exports.append(export)
else:
flag = True
if flag:
cfg["export"] = exports
return flag
def gen_tree(data_path):
root = {}
......@@ -54,18 +67,21 @@ def gen_tree(data_path):
yield no_dir, no_name
def ensure_id_helper(node):
flag = False
if (node.get('node_id') is None) or node.get('node_id') in id_set:
node['node_id'] = gen_node_id()
flag = True
id_set.add(node['node_id'])
if 'children' in node:
for c in node["children"]:
ensure_id_helper(list(c.values())[0])
flag = flag or ensure_id_helper(list(c.values())[0])
def ensure_node_id(cfg_path, cfg):
ensure_id_helper(cfg)
dump_json(cfg_path, cfg, exist_ok=True, override=True)
return flag
def ensure_node_id(cfg):
return ensure_id_helper(cfg)
def make_node(name, node_id, keywords, children=None):
node = {}
......@@ -80,7 +96,8 @@ def gen_tree(data_path):
# 根节点
cfg_path = os.path.join(data_path, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
if ensure_node_id(cfg):
dump_json(cfg_path, cfg)
tree_node = {
"node_id": cfg['node_id'],
"keywords": cfg['keywords'],
......@@ -92,47 +109,51 @@ def gen_tree(data_path):
for level_no_dir, level_no_name in list_dir(data_path):
print(level_no_dir)
no, level_name = parse_no_name(level_no_name)
cfg_path = os.path.join(level_no_dir, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
level_path = os.path.join(level_no_dir, 'config.json')
level_cfg = load_json(level_path)
if ensure_node_id(level_cfg) or check_export(level_no_dir, level_cfg):
dump_json(level_path, level_cfg, exist_ok=True, override=True)
level_node, level_node_children = make_node(
level_name, cfg['node_id'], cfg['keywords'])
tree_node['children'].append(level_node)
# 章节点
for chapter_no_dir, chapter_no_name in list_dir(level_no_dir):
no, chapter_name = parse_no_name(chapter_no_name)
cfg_path = os.path.join(chapter_no_dir, 'config.json')
ensure_node_id(cfg_path, cfg)
cfg = load_json(cfg_path)
chapter_path = os.path.join(chapter_no_dir, 'config.json')
chapter_cfg = load_json(chapter_path)
if ensure_node_id(chapter_cfg) or check_export(chapter_no_dir, chapter_cfg):
dump_json(chapter_path, chapter_cfg, exist_ok=True, override=True)
chapter_node, chapter_node_children = make_node(
chapter_name, cfg['node_id'], cfg['keywords'])
chapter_name, chapter_cfg['node_id'], chapter_cfg['keywords'])
level_node_children.append(chapter_node)
# 知识点
for section_no_dir, section_no_name in list_dir(chapter_no_dir):
no, section_name = parse_no_name(section_no_name)
cfg_path = os.path.join(section_no_dir, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
sec_path = os.path.join(section_no_dir, 'config.json')
sec_cfg = load_json(sec_path)
flag = ensure_node_id(sec_cfg) or check_export(section_no_dir, sec_cfg)
section_node, section_node_children = make_node(
section_name, cfg['node_id'], cfg['keywords'], cfg['children'])
section_name, sec_cfg['node_id'], sec_cfg['keywords'], sec_cfg['children'])
chapter_node_children.append(section_node)
# 确保习题分配了习题ID
for export in cfg['export']:
for export in sec_cfg["export"]:
ecfg_path = os.path.join(section_no_dir, export)
ecfg = load_json(ecfg_path)
if (ecfg.get('exercise_id') is None) or (ecfg.get('exercise_id') in id_set):
ecfg['exercise_id'] = uuid.uuid4().hex
dump_json(ecfg_path, ecfg, exist_ok=True, override=True)
id_set.add(ecfg['exercise_id'])
if flag:
dump_json(cfg_path, cfg, exist_ok=True, override=True)
# 保存技能树骨架
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册